Get IP Address List - CSharp Network

CSharp examples for Network:IP Address

Description

Get IP Address List

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 List<string> GetIPAddressList()
        {/* w  ww. j a  va2  s . c  o m*/
            List<string> ipAddressList = new List<string>();

            IPHostEntry ipHostEntrys = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
            foreach (IPAddress ip in ipHostEntrys.AddressList)
            {
                if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    ipAddressList.Add(ip.ToString());
                }
            }
            return ipAddressList;
        }
}

Related Tutorials