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

grep ip address from dhcpd.leases file using mac address

by varalaxmibbnl (Acolyte)
on Jan 11, 2014 at 10:40 UTC ( #1070243=perlquestion: print w/ replies, xml ) Need Help??
varalaxmibbnl has asked for the wisdom of the Perl Monks concerning the following question:

hi monks...

i have dhcp server which gives ip to few systems..using mac address how wil i find the ip address of that system from dhcpd.leases file via perl...

#dhcp.pl #!/usr/bin/perl #use strict; use Net::SSH::Perl; $hostname = "dhcp-server"; $username = "admin"; $password = "pswd"; $ssh = Net::SSH::Perl-> new ("$hostname", debug => 0); $ssh -> login ("$username","$password"); #$ssh -> cmd ("cd /var/lib/dhcp/"); @ar = $ssh -> cmd ("cd /var/lib/dhcp/ && cat dhcpd.leases |grep $ARGV[ +0]"); print "@ar";

when i run this script as

 perl dhcp.pl 12:34:56:78:90:32

i'm not getting the ip...is their any module which prints ip address assigned to particular mac address..please help me thank you

Comment on grep ip address from dhcpd.leases file using mac address
Select or Download Code
Re: grep ip address from dhcpd.leases file using mac address
by mmenza (Initiate) on Jan 11, 2014 at 11:47 UTC
    I think that you need to check two things:

    1) Is your ssh connection working? perhaps you can put the command '@ar=$ssh->cmd("hostname")` in your script (instead of the existing @ar= command) and see if you get any print output.

    2) Does the ssh login username and password, and the cd and cat commands (sent via $ssh->cmd) work if done manually?

    I might do this another way (using @ar = `ssh user@hostname 'cat /var/lib/dhcp | grep $ARGV[0]'` and having ssh keys in place to avoid needing a password, as per the man ssh keygen and google).

    Your way could/should work, might just need to troubleshoot a bit.
Re: grep ip address from dhcpd.leases file using mac address
by Laurent_R (Vicar) on Jan 11, 2014 at 13:57 UTC

    Maybe you simply need to chomp ARGV[0].

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2014-08-21 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (134 votes), past polls