private void ButtonIP_Click(object sender
System EventArgs e) { Syste
mNet IPAddress[] addressList = Dns GetHostByName(Dns GetHostName()) AddressList;
if ( addressListLength> )
{ TextLIPText = addressList[ ] ToString();
TextSIPText = addressList[ ] ToString();
}
else
{
TextLIPText = addressList[ ] ToString();
TextSIPText = 沒有可用的連接 ;
}
}
獲取服務器的IP地址與MAC地址另一方法如下
using System
Management;
string stringMAC =;
string stringIP =;
ManagementClass MC = new ManagementClassWin _NetworkAdapterConfiguration );
ManagementObjectCollection MOC= MCGetInstances();
foreach(ManagementObject MO in MOC)
{
if ((bool)MO[IPEnabled ] == true)
{
stringMAC += MO[MACAddress ] ToString();
TextMACText = stringMAC ToString();
string[] IPAddresses = (string[]) MO[IPAddress ];
if(IPAddressesLength > )
stringIP = IPAddresses[];
TextIPText = stringIP ToString();
}
}
獲取客戶端本機的IP地址相當簡易
using SystemNet;
TextIPText=Page Request UserHostAddress;
如要獲取客戶端本機的MAC地址就相對復雜些
From:http://tw.wingwit.com/Article/program/net/201311/15096.html