Get the MAC address through the IP address, it seems to be available for local area network

xiaoxiao2021-03-06  37

Public class classnetgetmac {public classnetgetmac () {}

[DllImport ( "Iphlpapi.dll")] private static extern int SendARP (Int32 dest, Int32 host, byte [] mac, ref Int32 length); [DllImport ( "Ws2_32.dll")] private static extern Int32 inet_addr (string ip );

///

/// Get a network card MAC address /// /// given the IP address /// corresponding IP NIC MAC Address Public Static String getMacByip (String IP) {Try {byte [] AA = New Byte [6];

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

INT64 MacInfo = New INT64 (); int32 len = 6; int res = sendarp (LDEST, 0, AA, REF LEN);

Return Bitconverter.Tostring (AA, 0, 6) ;; Catch (Exception Err) {throw Err;}}

}

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

New Post(0)