Procedure for ASP. NET to obtain MAC addresses and IP addresses

Source: Internet
Author: User

ASP. NET is simple and practical to obtain MAC addresses and IP addresses using DNS, as follows:

The following is a reference clip:

 
 
  1. Private VoidButtonIP_Click (object sender, System. EventArgs e)
  2. {System. Net. IPAddress [] addressList = Dns. GetHostByName (Dns. GetHostName (). AddressList;
  3. If(AddressList. Length> 1)
  4. {TextLIP. Text = addressList [0]. ToString ();
  5. TextSIP. Text = addressList [1]. ToString ();
  6. }
  7. Else
  8. {
  9. TextLIP. Text = addressList [0]. ToString ();
  10. TextSIP. Text ="No available connections";
  11. }
  12. }

ASP. NET:

The following is a reference clip:

 
 
  1. using System.Management;   
  2. string stringMAC = "";   
  3. string stringIP = "";   
  4. ManagementClass MC = new ManagementClass "Win32_NetworkAdapterConfiguration");   
  5. ManagementObjectCollection MOC= MC.GetInstances();   
  6. foreach(ManagementObject MO in MOC)   
  7. {   
  8. if ((bool)MO["IPEnabled"] == true)   
  9. {   
  10. stringMAC += MO["MACAddress"].ToString();   
  11. TextMAC.Text = stringMAC.ToString();   
  12. string[] IPAddresses = (string[]) MO["IPAddress"];   
  13. if(IPAddresses.Length > 0)   
  14. stringIP = IPAddresses[0];   
  15. TextIP.Text = stringIP.ToString();   
  16. }   
  17. }  

It is quite easy to obtain the IP address of the local client. The method is as follows:

The following is a reference clip:

 
 
  1. using System.Net;   
  2. 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?

  1. ActionInvoker of ASP. net mvc Framework
  2. Cause and solution of ASP. NET Session loss
  3. ASP. NET code hidden files
  4. Analysis on the personalization features of ASP. NET basic tutorials
  5. Analysis of ASP. net html Control Learning

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.