Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to automatically retrieve IP addresses

Status
Not open for further replies.

weloki

Technical User
Feb 19, 2004
12
US
Hi, where I work we are collecting info on our computers, and one thing we require is a listing of the latest IP addresses assigned to the users’ machines. They are mostly set to DHCP, so the idea I had was to check each machine every day with a script that would find their IP addresses, and then write the results to a file (and ideally enter those results into our database). I’ve found a perl script online ( that can check one machine at a time, if at all, but its behavior is strange; sometimes it just won’t display the IP, even when I’m using it as an administrator. Also, it relies on reading the Windows registry so it won’t work to get the IPs of our Macs. I was wondering if you could direct me to some place where I could get such a script, especially one that will work with our UNIX-based machines.
Thank you.
 
I guess the dhcp server should store the addresses it allocates in a file somewhere.
Find that and you should be able to parse it easily.




(very injured) Trojan.
 
Trojan,
What did you do yourself, to become (very injured) - Bikes?
--Paul

cigless ...
 
Nah, chopped my thumb up on a table saw whilst chopping up big chunks of wood.
Not feeling too good at all now! :-(




(very injured) Trojan.
 
Thanks TrojanWarBlade. How would I find the DHCP server? I work at a university and they are pretty strict with how they handle their servers. Would they really let me poke around their server with a script that ran every day?
 
From my linux system (man dhclient.leases)
DESCRIPTION
The Internet Systems Consortium DHCP client keeps a persistent database
of leases that it has acquired that are still valid. The database is
a free-form ASCII file containing one valid declaration per lease. If
more than one declaration appears for a given lease, the last one in
the file is used. The file is written as a log, so this is not an
unusual occurrance.

The format of the lease declarations is described in dhclient.conf(5).

FILES
/var/lib/dhcp/dhclient.leases
See if you have a /var/lib/dhcp/dhclient.leases file and if so, see if you can read it.





(very injured) Trojan.
 
Have you tried this?

use Net::Address::IPv4::Local;

# Get the local system's IP address that is "connected" to "the internet":

my $address = Net::Address::IPv4::Local->public;
print "IP:$address\n";


Mike

You cannot really appreciate Dilbert unless you've read it in the
original Klingon.

Want great answers to your Tek-Tips questions? Have a look at faq219-2884

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top