日期:2014-05-19  浏览次数:20829 次

不用dns 怎样获得本机的ip?急 在线等
不用dns   怎样获得本机的ip?   用Winform

------解决方案--------------------
WMI技术,参考代码:
using System.Management;


listBox1.Items.Clear();

ManagementObjectSearcher query =
new ManagementObjectSearcher(
"select * from Win32_NetworkAdapterConfiguration where IPEnabled= 'TRUE ' ");
ManagementObjectCollection queryCollection = query.Get();
foreach (ManagementObject mo in queryCollection)
{
string[] addresses = (string[])mo[ "IPAddress "];
string[] subnets = (string[])mo[ "IPSubnet "];
string[] defaultGateways = (string[])mo[ "DefaultIPGateway "];
listBox1.Items.Add( "Network Card: " + (string)mo[ "Description "]);
listBox1.Items.Add( "MAC Address: " + (string)mo[ "MACAddress "]);
if (addresses != null)
foreach (string ipaddress in addresses)
{
listBox1.Items.Add( "IP Address: " + ipaddress);
}
if (subnets != null)
foreach (string subnet in subnets)
{
listBox1.Items.Add( "Subnet Mask: " + subnet);
}
if (defaultGateways != null)
foreach (string defaultGateway in defaultGateways)
{
listBox1.Items.Add( "Gateway: " + defaultGateway);
}
listBox1.Items.Add( " ");
}