Obtain the Server IP address and MAC address

Source: Internet
Author: User
The DNS method is simple and practical to obtain the IP address of a server, as follows:

The following is a reference clip:
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:

The following is a reference clip:
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:

The following is a reference clip:
Using system. net;
Textip. Text = page. Request. userhostaddress;

To obtain the MAC address of the client's local machine, it is more complicated to import and call two APIs and use ARP to obtain the MAC address of the machine in the same network segment, for cross-network profit, use the IP scan or the nbtstat command in cmd to obtain the MAC address. You can also obtain it by reading the system registry value or WMI database.

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.