1.
ArrayList alAllLocalIp = new ArrayList();
System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_NetworkAdapterConfiguration");System.Management.ManagementObjectCollection nics = mc.GetInstances();
foreach (System.Management.ManagementObject nic in nics)
{
if (Convert.ToBoolean(nic["ipEnabled"]) == true)
{
string IpAddress = (nic["IPAddress"] as String[])[0].ToString();
if (!alAllLocalIp.Contains(IpAddress) && IpAddress.Trim()!="0.0.0.0")
{
alAllLocalIp.Add(IpAddress);
}
}
}
2.
ArrayList alAllLocalIp = new ArrayList();
string strHostName = Dns.GetHostName(); //得到本机的主机名
IPHostEntry ipEntry = Dns.GetHostByName(strHostName); //取得本机IP
for (int i = 0; i < ipEntry.AddressList.Length; i++)
{
alAllLocalIp.Add(ipEntry.AddressList[i].ToString());
}