ASsp. Net

Source: Internet
Author: User

The DNS method is simple and practical to obtain the IP address of a server, 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 available connections ";
}
}

Another method to obtain the Server 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 quite easy to obtain the IP address of the local client. The method is as follows:
Using System. Net;
TextIP. Text = Page. Request. UserHostAddress;

To obtain the MAC address of the local client, it is more complex. You must import and call two APIs and use ARP to obtain the MAC address.

For the MAC address of a machine in the same network segment, use the IP address scan or the nbtstat command in cmd to obtain the MAC address for the profit of cross-network segments. You can also read the System Registration

Table value or WMI database. If you have a simple and feasible solution, please comment below for discussion.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.