Get MAC address troubles

Source: Internet
Author: User

Obtain the MAC address of the C # implementation introduced in attack networkCode, But the result is different from what you think.
[Dllimport ("iphlpapi. dll")]
Private Static 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 );

Private void test _ click (Object sender, system. eventargs E)
{
Int32 ldest = inet_addr ("192.168.10.42"); // ip address of the destination
Int32 lhost = inet_addr ("192.168.10.42"); // local IP Address

Try
{
Byte [] macinfo = new byte [6];
Int32 length = 48;

Intptr MAC = new intptr (macinfo [0]);
Intptr Len = new intptr (6 );

int II = sendarp (ldest, lhost, ref Mac, ref Len);
response. write (Mac. tostring ();
}< br> catch (exception ERR)
{< br> response. write (err. message );
}< BR >}< br> the number of the obtained NIC address is 1078779904
however, the actual MAC address is 00e04c4031c0
the conversion between the decimal and hexadecimal numbers cannot be performed. matching
incomprehension of the intptr type is even more annoying
I don't know if I can get expert advice

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.