Get the MAC address of the LAN computer using the function Sendarp ()

Source: Internet
Author: User
Tags sprintf

Sendarp

31 indicates that the other party does not boot, our function does not detect it,

1784 the value of the last argument to the function is 0, or your given value does not match the buffer size you gave.

If return 31 is not a line, the last parameter pointer points to a value of 0

The function has one drawback :

This function essentially sends an ARP request packet to the target host and then gets the reply packet to update the MAC, but the send-side IP and Mac in the ARP Request packet are native IP and Mac, so the other side arp-a to view the cache table with my Ip-mac mapping record in the record. It is easy to know if someone is scanning their machine, or the ARP virus is also possible.

The problem with solving this function is to forge the package yourself, but the MAC address must be correct, otherwise the reply packet will not be sent to the native ~

UpdateData (TRUE);  if (M_straddr.isempty ()) {AfxMessageBox ("Please fill in the host IP address to find the MAC address"); Return } unsigned long uladdr = inet_addr (M_STRADDR); unsigned long ulmac[2]; unsigned long ullen = 6; DWORD Dwretval =Sendarp(uladdr, 0, Ulmac, &ullen);        if (Dwretval = = no_error) {size_t I, J;        char * Szmac = new Char[ullen*3];  Pbyte Pbhexmac = (pbyte) Ulmac;        for (i = 0, j = 0; i < ulLen-1; ++i) {J + = sprintf (Szmac + J, "%02x:", Pbhexmac[i]);  } sprintf (Szmac + J, "%02x", Pbhexmac[i]);  M_strmac = Szmac; delete [] Szmac; } updatedata (FALSE);

Get the MAC address of the LAN computer using the function Sendarp ()

Related Article

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.