views:

2668

answers:

10

I'm working on a Wake on LAN service that will run from a web site and should interact with many different platforms - therefore, no Windows-only solutions. When a user registers their system with the web site, I need to get the MAC address to use in constructing the "magic" packet. I have a Java Applet that is able to do this for me and am aware of an ActiveX control that will work, but I'm wondering if there is a way to do this server-side by querying routers/switches. Since the system may be on any of a number of different physical subnets, using ARP won't work -- unless there's a way to configure the router(s) to perform the ARP on my behalf.

Anyone know of any network APIs, proprietary or otherwise, that can be used to look up MAC addresses given an IP address? I think we're using Cisco routers, but it's a complicated network and there may be multiple vendors involved at various levels. I'd like to get some background information on possible solutions before I go to make a sacrifice to the network gods. No point in abasing myself if it's not technically possible. :-)

EDIT: We do have the network infrastructure set up to allow directed broadcast, though figuring out the exact broadcast address since netmasks are not always /24 is another conundrum that I need to solve.

+2  A: 

If you are on a local network that uses DHCP you might be able to look in the servers database to get the MAC of the last user with that address. In the future you could watch the network for ARP requests and cache the responses in some sort of table. You might also look at using RMON or SNMP to try and query the Address Tables on the switches and routers.

It should be noted that to use WoL across routers you either need to enable Directed Broadcasts or you need to have a relay server in the local segment.

Been a while since I played routers and swtiches but this might be a starting point for what to query using SNMP http://www.cisco.com/en/US/tech/tk648/tk362/technologies_tech_note09186a00801c9199.shtml

Matthew Whited
The directed broadcast thing is already taken care of. We have an SCCM-based system that works for managed Windows systems and will let an admin do this, but I'm working on a way for users to wake their own systems up to support remote desktop/remote login in a multiplatform world.
tvanfosson
What DHCP server do you use?
Matthew Whited
You could also give users instructions on how to get their MAC address and use that has part of the registation for the service
Matthew Whited
I work at a University and we have many non-technical people that would probably be using this. I'd like to make it as simple and easy to use as possible -- preferably point and click if possible.
tvanfosson
You could have a simple tool for them to run on the workstation and pregesiter them with their username and MAC address. Might need a different script per platform but you might be able to do it in Java as well (I havn't done enough in Java to even begin to know where to start)
Matthew Whited
A: 

I don't think there is any way to accomplish this. When the IP packet goes via the first router the host's MAC information is lost (as you know MAC is only used in ethernet layer). If the router most close to your PC was capable of telling the remote MAC code to you, again it would only see the MAC of the next router between your PC and the "other end".

tputkonen
I'm hoping that some network management tools might have the ability to do query all network components for me.
tvanfosson
Really, I'd talk to your network people and see what the network infrastructure can do for you. I'd try to combine this with however you're currently keeping track of these computers right now. See if you can arrange to add "MAC Address" as a new column to your current "network devices" database, as an example. You could then easily choose which devices to wake, send the broadcasts, make sure they wake up, etc.
John Saunders
A: 

Start sacrificing.

There's no general way to do this in terms of the network unless you have no routers involved. With a router involved, you will never see the MAC address of the originating system.

This assumes that the originating system only ever has a single network interface, so has only a single MAC address.

In fact, are you even sure that your "magic packet" (whatever that is) will reach the system you want it to reach, through the routers? That sounds like a function the routers or other network infrastructure should be performing.

John Saunders
Wake on LAN packet has to contain the MAC address in the payload:http://en.wikipedia.org/wiki/Wake_on_lan#Magic_Packet
tputkonen
Ok, so it looks like, in an IP network, this will be multicast to the subnet the machine is on. Still, the MAC address won't come past the router, so you'll have to get it elsewhere.
John Saunders
Looks like you got hit by a drive-by-down-voter
Matthew Whited
@Matthew: It happens. Frequently.
John Saunders
+1  A: 

I don't know if these might be helpful but take a look:

http://www.webdeveloper.com/forum/showthread.php?t=134120

http://www.qualitycodes.com/tutorial.php?articleid=19

ian
Thanks. I'm familiar with the WMI/ActiveX way and I already have a Java Applet that will work. I'm looking for something that would allow me to do this from the server, though.
tvanfosson
A: 

Mac address is only used on network segments, and is lost at each hop. Only IP is preserved for end-to-end - and even then the from ip address is rewritten when Natted. I guess my answer is, not possible unless everything is on the same network segment, or your routers are set up for proxy arp (which is not really realistic).

nikudesu
+1  A: 

You've said everything I can think of...

The source MAC address changes as a packet hops from device to device so unless the client is on the same subnet, the server won't be able to get the MAC address. (You would do it via ARP)

A signed java applet or activex control would be the easiest solution. It would be able to (almost passively) get all the networking info you need (IE doesn't even prompt to run a signed applet)

If you are fully aware of the network that is using the service then you could probably query a gateway's client-list via SNMP or CDP. You would be able to map out IP-Addresses to MAC addresses... but this is really vendor dependent (but common) and wouldn't be much better (imo) than having an applet.

Patrick Gryciuk
I'm leaning toward the Java solution currently, but it requires Java 6 to get the hardware address, so it's not ideal. Who knows what version people will have installed and it's not even supported on MacOS yet.
tvanfosson
Well a more complicated approach that could use older versions of java would be to figure out which OS they are running and to download system-specific libraries and use JNI that could get the MAC address.
Patrick Gryciuk
A: 

You can only get MAC entries in the ARP table for machines on the same network. If you connect to a machine via a router then you will only see the routers MAC address in the ARP table. So there is no way of knowing the foreign host’s MAC address unless it's a host on the same network (no routers involved).

And by the way there are many similar question already on SO.

lothar
A: 

if it's a windows system you can use NBTSTAT -A this will return the netbios info and the IP is there

any Management system like SMS or Altiris will have this info

The DHCP server is a good idea

If it's local you can ping it and then quickly run ARP -a look for the IP and the MAC will be there. you might need to write a small batch file.

if you have access to the PC you can use WMI to access the info for the Nic with DHCP.

+1  A: 

Currently the application is using a Java 6 applet that allows me to extract both the hostname and the MAC address from the remote system. I don't like having this dependency on Java 6, but Snow Leopard and Windows both support it, so I can probably live with it.

On a related-front our networking folks approached me for some help with converting some existing code to ASP.NET. During the conversation I asked if they had live MAC address information (since they do port shutoffs based on suspicious network activity -- viruses/worms). Turns out they do and we may be able to leverage this project to get access to the information from the network database.

tvanfosson
A: 

As said above we can get mac address from a known IP address if that host is in the same subnet. First ping that ip; then look at arp -a | grep and parse the string on nix* to get mac address.

We can issue system command from all programming languages standard API's and can parse the output to get mac address.Java api can ping an IP but I am not sure if we parse the ping output(some library can do it). It would be better to avoid issuing system command and find an alternative solution as it is not really Platform Independent way of doing it.

Courtesy: Professor Saleem Bhatti

Sandeep