110,576
社区成员
发帖
与我相关
我的任务
分享
//试试这个
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface ni in interfaces)
{
if (ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
{
foreach (UnicastIPAddressInformation ip in
ni.GetIPProperties().UnicastAddresses)
{
if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
MessageBox.Show(ip.Address.ToString());
}
}
}
}
using System.Net.NetworkInformation;
。
。
。
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface ni in interfaces)
{
if (ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
{
MessageBox.Show(ni.Name);
}
}
string strHostName = Dns.GetHostName();
foreach (IPAddress ip in System.Net.Dns.GetHostAddresses(strHostName))
{
Console.WriteLine(ip.ToString());
}