Using C # to write a method for obtaining remote IP,MAC

Source: Internet
Author: User
If you want to get a remote address, you need to use sendarp this function to implement. 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");/IP of destination
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);
}


Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.