NetworkInterface[] interfaces = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
int len = interfaces.Length;
for (int i = 0; i < len; i++)
{
NetworkInterface ni = interfaces[i];
if (ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
{
if (ni.Name == "本地连接")
{
IPInterfaceProperties property = ni.GetIPProperties();
foreach (UnicastIPAddressInformation ip in
property.UnicastAddresses)
{
if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
localIP = ip.Address.ToString();
}
}
}
}
}
C#获取本地连接IP地址
最新推荐文章于 2023-12-20 21:20:48 发布