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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get the IP Address of a server?

Little tricks

How do I get the IP Address of a server?

by  missbarbell  Posted    (Edited  )
If you need to find out the IP Address of the server, upon which your script is running, try the following code snippet:


#!/usr/bin/perl -w
use strict;

use Socket 'inet_ntoa';
use Sys::Hostname 'hostname';
my $addr = inet_ntoa(scalar gethostbyname(hostname() || 'localhost'));
print "$addr\n";


This uses Perl core modules, so you shouldn't need to do any installing.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top