Because of business needs, you need to register some of the terminal to ensure that the license terminal can log in to the business system. The best way is to record the MAC address of each terminal to verify whether it is authorized.
Here is the MAC address of the terminal that is used to get the specified IP of the terminal:
[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);
public static string GetNetCardAddress (string strIp) {try {IPHostEntry host = Dns.GetHostByName (System.Environment.MachineName); Int32 local = inet_addr (host.AddressList [0] .ToString ()); Int32 remote = inet_addr (strIp);
INT64 Macinfo = New INT64 (); INT32 Length = 6; Sendarp (Remote, Local, Ref MacInfo, Ref Length);
String Temp = System.convert.toString (MacInfo, 16) .padleft (12, '0'). TouPper ();
Stringbuilder strreturn = new stringbuilder (); int x = 12; for (int i = 0; i <6; i ) {strreturn.append (Temp.substring (x-2, 2)); x - = 2;}
Return strreturn.toString ();} catch (exception error) {throw new exception;}}
After using a period of time, it is found that the MAC address that can only be obtained only by the same network segment or the terminal of any route, and the MAC address of the different network segment or the route is not normal to the MAC address. The following operating system command can solve this problem:
Public static string getnetcardaddress22 (string strip) {string mac = ""
System.Diagnostics.Process process = new System.Diagnostics.Process (); process.StartInfo.FileName = "nbtstat"; process.StartInfo.Arguments = "-a" strIp; process.StartInfo.UseShellExecute = false; process.StartInfo .CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; process.Start (); string output = process.StandardOutput.ReadToEnd (); int length = output.IndexOf ( "MAC Address ="); if (length> 0) {Mac = Output.substring (Length 14, 17);} process.waitforeXIT (); return mac.replace ("-", "") .trim ();