public string GetIPAddress()
{
try
{
string sIP = string.Empty; //获取IP地址
_mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
_moc = _mc.GetInstances();
foreach (ManagementObject mo in _moc)
{
if ((bool)mo["IPEnabled"] == true)
{
Array ar;
ar = (System.Array)(mo.Properties["IpAddress"].Value);
sIP = ar.GetValue(0).ToString();
if (sIP == "0.0.0.0") continue;
break;
}
}
_moc = null;
_mc = null;
return sIP;
}
catch { return string.Empty; }
}