Solved

Winsock -> Obtaining a remote mac address

Posted on 2004-07-30
6
1,152 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now