ASP. NET is simple and practical to obtain MAC addresses and IP addresses using DNS, as follows:
The following is a reference clip:
- Private VoidButtonIP_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";
- }
- }
ASP. NET:
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 read the system registry value or WMI database. If you have a simple and feasible solution, please leave a message to me.
ASP. NET introduces how to obtain MAC addresses and IP addresses. Does ASP. NET know about MAC addresses and IP addresses?
- ActionInvoker of ASP. net mvc Framework
- Cause and solution of ASP. NET Session loss
- ASP. NET code hidden files
- Analysis on the personalization features of ASP. NET basic tutorials
- Analysis of ASP. net html Control Learning