If you get the MAC address of the server

Source: Internet
Author: User
Tags tostring
Server

Realize

1, new project Getmac;

2, in the Solution Explorer, modify the default WebForm1.aspx for Getmac.aspx;

3, in Solution Explorer, add a reference to the project, add System.Management;

4. In the Toolbox, drag and drop a label into the Design view, named MACAddress, to display the read MAC address information;

5, in the post file, add the following methods:
private static string Get_macaddress ()
{
String Mac_address= "";
ManagementObjectSearcher Query =new managementobjectsearcher ("SELECT * from Win32_NetworkAdapterConfiguration");
Managementobjectcollection querycollection = query. Get ();
foreach (ManagementObject mo in querycollection)
{
if (mo["ipenabled"]. ToString () = = "True")
{
mac_address = mo["MacAddress"]. ToString ();
}
}
return mac_address;
}

Then add a line of code to Page_Load:

Macaddress.text = Get_macaddress ();

So we can get the MAC address of the machine, the format is xx:xx:xx:xx:xx, we can convert to xx-xx-xx-xx-xx or other forms.

Application

We can generate a unique serial number by reading the MAC address of the machine, the hard drive number, the CPU, or other hardware information, and then encrypting it with the encryption method we write, so that when we deploy the Web application, we have to register it with the traditional C/ S-structured software registers the same effect.




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.