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

Getting Ip Address

by flamel (Initiate)
on Apr 04, 2007 at 19:42 UTC ( #608360=perlquestion: print w/replies, xml ) Need Help??

flamel has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I need to discover the ip address of a remote network device in my internal network(I know his Mac Address).
Is there a way do that in perl?

Thanks in Advance.

Replies are listed 'Best First'.
Re: Getting Ip Address
by Joost (Canon) on Apr 04, 2007 at 19:57 UTC
      I suppose that you could ping all the IP addresses in your local subnet and then check the arp cache
      fyi, often pinging the broadcast address (ie, will suffice for this.
Re: Getting Ip Address
by shmem (Chancellor) on Apr 04, 2007 at 19:56 UTC
    Sure, just search CPAN (Arp)...


    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: Getting Ip Address
by tirwhan (Abbot) on Apr 04, 2007 at 21:19 UTC

    Non-perl solution, but if this is something you need to do often I recommend running arpwatch on a machine that is always connected to the network. You can then simply retrieve the IP address under which a given MAC last showed up from the arpwatch database.

    Alternatively (if you really just want to do this once), you can use the arping utility to check every IP address on your network segment until you get a response with the matching MAC address. This puts less load on the network than similar solutions using nmap or ICMP ping because only the initial ARP request is sent and no further packets (this also means it's a lot faster on large networks). arping also has an option to search for a MAC address directly, but that relies on the host in question to respond to an ICMP broadcast ping, which many hosts will not be configured to do.

    All dogma is stupid.
Re: Getting Ip Address
by gt8073a (Hermit) on Apr 04, 2007 at 20:48 UTC

    If your on a switched network, you'll need to get mac addresses from the switches. Look into Net::SNMP, or Net::Telnet, or even Net::SSH.

    Remember, the mac may been flushed from a device's memory if it hasn't been seen in a while. So, you may need to ping sweep your entire network. nmap, unicorn, or paketto are 3 pretty well known scanners to check out.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://608360]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2021-02-25 17:14 GMT
Find Nodes?
    Voting Booth?

    No recent polls found