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.