Solved

Winsock -> Obtaining a remote mac address

Posted on 2004-07-30
6
1,165 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

791 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