Get IP Address - CSharp Network

CSharp examples for Network:IP Address

Description

Get IP Address

Demo Code

// All Rights Reserved , Copyright (C) 2012 , Hairihan TECH, Ltd. 
using System.Net.NetworkInformation;
using System.Net;
using System.Management;
using System.Collections.Generic;

public class Main{

        public static string GetIPAddress()
        {//from   w  w  w .ja va 2 s.c om
            string ipAddress = string.Empty;
            System.Net.IPHostEntry ipHostEntrys = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
            List<string> ipList = GetIPAddressList();
            foreach (string ip in ipList)
            {
                ipAddress = ip.ToString();
                break;

            }
            return ipAddress;
        }
}

Related Tutorials