Get all IP address from the system in C# with Sample



Get all IP addresses from adopters.

 public  List<string> GetIPAddresss()
        {
           List<string> listOfIpaddress=new List<string>();
            try
            {
                foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
                {
                    if (ni.OperationalStatus == OperationalStatus.Up && (ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 
                            || ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet))
                    {
                        foreach (UnicastIPAddressInformation ip in ni.GetIPProperties().UnicastAddresses)
                        {
                            if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                            {

                              listOfIpaddress.Add(ip.Address.ToString());
                               
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHandler.PrintLog(ex.StackTrace);
            }
            return listOfIpaddress;
        }

0 Comment's

Comment Form

Submit Comment