取得本機網路IP:
System.Net.IPAddress[] addressList = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName( )).AddressList;
string s="";
for ( int i = 0; i < addressList.Length; i++ )
{
s += addressList[i].ToString( ) + "\n";
}
textBox1.Text = s ; //顯示 IP
取得網卡序號:
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstance();
string str="";
foreach( ManagementObject mo in moc )
{
if((bool)mo["IPEnabled"] == true) str = mo["MacAddress"].ToString();
}
return str ; //返回網卡序號
是否存在網路:
SystemInformation.Network == true //已連上網路
== false //未連上網路
網路連線狀態:
SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.OffLine //離線
== PowerLineStatus.OnLine //連線
== PowerLineStatus.Unknown //未知
沒有留言:
張貼留言