Gets the MAC address of the terminal for the specified IP
Source: Internet
Author: User
Because the business needs, the company needs to register some terminals to ensure that authorized terminals can log into the business system, the best way is to record the MAC address of each terminal to verify whether there is authorization.
The following is the MAC address of the terminal that gets the specified IP in the form of a calling API:
[DllImport ("Iphlpapi.dll")]
public static extern int Sendarp (Int32 dest, Int32 host, ref Int64 Mac, ref Int32 length);
Dest is the IP of the target machine; Host is the IP of this machine
[DllImport ("Ws2_32.dll")]
public static extern Int32 inet_addr (string IP);
After using the above method for a period of time, it is found that only the MAC address of the terminal that has the same network segment or no route is obtained, while the MAC address of those terminals with different network segments or routes is not properly obtained. The following operating system command method resolves this issue:
public static string GetNetCardAddress2 (String strIp)
{
String mac = "";
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.