Solved

Winsock -> Obtaining a remote mac address

Posted on 2004-07-30
6
1,173 Views
Last Modified: 2013-12-03
Is it possible to get a remote computer's MAC Address upon recieving a packet VIA a udp socket? I know that the mac address gets sent along with the UDP header, but is there a way to look at it using winsock?

Note that this doesn't involve LANs at all.
0
Comment
Question by:Pogo187
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:mxjijo
ID: 11695118

No you cannot find it from the UDP packet because by the time your applications get the
packet, the IP/UDP etc headers are already removed.

To map between IP and MAC address, you may use ARP (Address resolution Protocol)

Take a look at SendARP (). I think that function would serve your purpose.

~j
0
 
LVL 8

Expert Comment

by:adg080898
ID: 11759047
This is somewhat cheesy, (use mxjijo's suggestion if you can, it's way better!), but an extremely simple alternative is to system() out to "arp -a", kind of like this:

system("arp -a > c:\\full\\path\\to\\my\\outputfile.txt");

Then open that output file and parse out the ARP information. Go into a command prompt and type

arp -a

and look at the output. Yes, I know, "UNIX style", but it should work if you start ripping your hair out trying to use SendARP.

I'm pretty sure you can't get the MAC address of a machine outside your local (hardwired) network. In other words, you won't see "past" a router.
0
 
LVL 8

Expert Comment

by:adg080898
ID: 11759052
How does it not involve LANs? In that case, you will probably only get the "mac address" for your modem. I know, it's not really a MAC address, but it pretends to have one.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 8

Assisted Solution

by:mxjijo
mxjijo earned 200 total points
ID: 11774361

adg,
     
>> I know, it's not really a MAC address, but it pretends to have one.
      Yes, any network interface (eithernet card / satellite link etc) will expose a unique MAC address, just like the IP address.
In fact you have to subcribe the MAC address before you use it.

>> I'm pretty sure you can't get the MAC address of a machine outside your local (hardwired) network
      Yes, that is the whole point of your default gateway. If the source machine could not find the MAC address in the network, it will forward it to the default gateway.

>> Yes, I know, "UNIX style", but it should work if you start ripping your hair out trying to use SendARP.
      Making a single call (system call in unix terms) is much better than parsing a txt file :)

0
 
LVL 8

Accepted Solution

by:
adg080898 earned 300 total points
ID: 11774500
SendARP requires windows 2000 Professional or XP.

I just noticed something in your question:
>  ...I know that the mac address gets sent along with the UDP header...

Actually, no. It doesn't get sent with the UDP header. The UDP datagram is wrapped in an ethernet frame that is addressed to YOUR mac address. Long before you get it (in winsock), the ethernet header is long gone.

If you did somehow manage to get a source mac address, it would be the mac address of the last router that touched your packet, useless.
0
 

Author Comment

by:Pogo187
ID: 11803887
Ah, I see. Thanks for the information.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question