Get each other's MAC address

xiaoxiao2021-03-06  62

Using system; using system.runtime.interopservices;

class Program {[DllImport ( "Iphlpapi.dll")] private static extern int SendARP (Int32 dest, Int32 host, ref Int64 mac, ref Int32 length); [DllImport ( "Ws2_32.dll")] private static extern Int32 inet_addr ( String IP);

Static Private INT64 GetRemoteMac (String Remoteip) {INT32 LDEST = INET_ADDR (Remoteip); // Destination IP

Try {int64 macinfo = new int64 (); int32 len = 6; int res = sendarp (LDEST, 0, REF MACINFO, REF LEN); RETURN MACINFO;} catch (Exception Err) {Console.Writeline ("error: {0 } ", err.message);} return 0;}

Static void main () {Console.write ("IP:"); int64 mac = getRemoteMac (console.readline ()); console.writeLine ("Mac: {0}", Convert.TOSTRING (Mac, 16)); }

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

New Post(0)