Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: How can I find a MAC address from aremote IP ?

by lhoward (Vicar)
on Mar 30, 2001 at 22:32 UTC ( #68459=note: print w/ replies, xml ) Need Help??


in reply to How can I find a MAC address from aremote IP ?

I can think of a few ways, but they're kind of out there and won't work most of the time:

  • If the remote box is running SNMP and you know its community string you can SNMP poll it to get its mac address
  • If the entire path from you to the remote host is IPv6 and not IPv4, the boxes MAC address is part of its IPv6 address by default (this can easily be overridden).
Why do you need the remote box's MAC address? If you're trying to use MAC address to uniquely identify users or something like that MAC (or any type of network address) is not the way to do it.


Comment on Re: How can I find a MAC address from aremote IP ?
Re: Re: How can I find a MAC address from aremote IP ?
by magoo (Initiate) on Mar 31, 2001 at 00:01 UTC
    Sometimes I need to locate quickly a computer in the buidling and the only information I have at first, is the IP address (and most of the time, it's a DHCP IP address, so there is many places possible it could be).

    With the MAC address, it's easy to locate on which port of a switch it is plugged. And when i know on which port of the switch it is plugged, I know where in the building the computer is. There's many switchs and routers, so I wanted to have a little perl script which would quickly gather all the informations on a machine.

    I think my problem is more how to use SNMP to get what I want than a Perl one. Net::SNMP seems the way to do it. I just need to find how, but that's not a perl issue now :)

      Sounds to me like you have 2 possible angles to attack this problem:
      • use SNMP to query the switches to see which IP is on which port. Its been a long time since I've written an SNMP poll for a switch, but if I remmember right I think the info you want is in the Bridge MIB.
      • The static IP's should be pretty easy to locate. For the dynamics you could query the DHCP server(s) to see what MAC a particular IP is assigned to. This may or may not be doable (and may or may ont be doable via SNMP), it depends on the capability of your DHCP server.
      On the other hand, there is a mac address to ip address mapping in snmp mib variables (as long as your switch supports it). Without looking it up, it might be something like PhysAddrToInetAddr. ....

      Nope, wait, after just looking it up, ip.ipNetToMediaTable.ipNetToMediaEntry.* is what you want.

      snmpwalk <switchname> <communityname> IpNetToMediaEntry

      Will list all (I believe) ports, which ip address is on that port, and which mac address is associated with that ip address.

      That could help, I guess.

      riffraff

        One thing I wanted to add, different companies support different mib variables, even though there is a standard. Bay Networks (Nortel Networks now) puts most of their stuff in the private enterprise variables, so the above information may need to be modified.

        riffraff

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://68459]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2014-12-22 03:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (110 votes), past polls