Get Current Ip Address : IP Address « Network « C# / C Sharp






Get Current Ip Address

   
///////////////////////////////////////////////////////////////////////////////////////////////
//
//    This File is Part of the CallButler Open Source PBX (http://www.codeplex.com/callbutler
//
//    Copyright (c) 2005-2008, Jim Heising
//    All rights reserved.
//
//    Redistribution and use in source and binary forms, with or without modification,
//    are permitted provided that the following conditions are met:
//
//    * Redistributions of source code must retain the above copyright notice,
//      this list of conditions and the following disclaimer.
//
//    * Redistributions in binary form must reproduce the above copyright notice,
//      this list of conditions and the following disclaimer in the documentation and/or
//      other materials provided with the distribution.
//
//    * Neither the name of Jim Heising nor the names of its contributors may be
//      used to endorse or promote products derived from this software without specific prior
//      written permission.
//
//    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
//    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
//    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//    IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
//    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
//    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
//    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
//    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
//    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
//    POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace WOSI.Utilities
{
    public class NetworkUtils
    {

        public static string GetCurrentIpAddress()
        {
            string hostname = Dns.GetHostName();

            IPAddress[] ips = Dns.GetHostAddresses(hostname);

            string ip = String.Empty;

            if (ips.Length > 0)
            {
                ip = ips[0].ToString();
            }

            return ip;
        }
    }
}

   
    
    
  








Related examples in the same category

1.IPAddress AddressFamily
2.Parse an IPAddress
3.Loopback IPAddress
4.Broadcast IPAddress
5.Any IPAddress
6.None IPAddress
7.IsLoopback IPAddress
8.IP Address parse, lookup IP Address parse, lookup
9.IPEndPoint sampleIPEndPoint sample
10.Get Host By Name, Get Host Name
11.Get Host Entry
12.Parse Host String
13.Get Host IP Address
14.Get IP address by query whatismyip.com
15.Get Local IP Address
16.IP to value
17.Get user IP from HttpContext
18.IP to Uint
19.UInt32 To IP Address
20.IP Address To UInt 32
21.Get IP address from notation (xxx.xxx.xxx.xxx) or hostname
22.Gets my local IP address (not necessarily external) and subnet mask
23.Returns true if the IPEndPoint supplied is on the same subnet as this host
24.Is Ip Address By Regular Expression
25.Checks if a given string is a valid IP address.
26.IP Address To NumberIP Address To Number
27.Get the description of a Enum value.
28.Get Subnet Mask
29.Get Available Socket Port