Write how to obtain remote IP, Mac with C #

xiaoxiao2021-03-06  54

If you want to get a remote address, you need to use the Sendarp function. The specific code is as follows:

[DLLIMPORT ("iPhlpapi.dll")]]]]]

Private Static Unsafe Extern Int Sendarp (INT32 DEST, INT32 HOST, REF INTPTR MAC, Ref INTPTR LENGTH);

[DLLIMPORT ("WS2_32.dll")]]]

Private static extern INT32 INET_ADDR (String IP);

INT32 LDEST = INET_ADDR ("157.60.68.163"); // Destination IP

INT32 LHOST = INET_ADDR ("157.60.68.33"); // Local IP

Try

{

Byte [] macinfo = new byte [6];

INT32 Length = 6;

INTPTR MAC = New INTPTR (MacInfo [0]);

INTPTR LEN = New INTPTR (6);

INT II = Sendarp (LDEST, LHOST, REF MAC, REF LEN);

Console.WriteLine ("Mac Add:" Mac);

Console.writeline ("Length:" LEN);

}

Catch (Exception Err)

{

Console.writeLine (ERR);

}

转载请注明原文地址:https://www.9cbs.com/read-116663.html

New Post(0)