Asp.net| Tips
The method of obtaining the IP address of the server is simple and practical by DNS method, as follows:
private void Buttonip_click (object sender, System.EventArgs e)
{system.net.ipaddress[] AddressList = Dns.gethostbyname (Dns.gethostname ()). AddressList;
if (addresslist.length>1)
{textlip.text = addresslist[0]. ToString ();
Textsip.text = addresslist[1]. ToString ();
}
Else
{
Textlip.text = addresslist[0]. ToString ();
Textsip.text = "no connections available";
}
}
Another way to get the server's IP address and MAC address is as follows:
Using System.Management;
String stringmac = "";
String STRINGIP = "";
ManagementClass MC = new ManagementClass "Win32_NetworkAdapterConfiguration");
Managementobjectcollection moc= MC. GetInstances ();
foreach (ManagementObject MO in MOC)
{
if ((bool) mo["ipenabled"] = = True)
{
Stringmac + = mo["MACAddress"]. ToString ();
Textmac.text = Stringmac.tostring ();
String[] ipaddresses = (string[]) mo["IPAddress"];
if (Ipaddresses.length > 0)
STRINGIP = Ipaddresses[0];
Textip.text = Stringip.tostring ();
}
}
It is fairly easy to get the IP address of the client native, as follows:
Using System.Net;
textip.text=page.request.userhostaddress;
If you want to get the client local MAC address is relatively more complex, have to import two API, use ARP protocol to obtain, but this can only get to the same network segment of the machine Mac, for the cross section of the use of IP scanning or cmd nbtstat command to obtain the MAC address. It can also be obtained by reading the system registry value or the WMI database. Please let me know if you have any easy and workable methods.