You want to find your (fully qualified) hostname.
use Sys::Hostname; $hostname = hostname();
use POSIX qw(uname); ($kernel, $hostname, $release, $version, $hardware) = uname(); $hostname = (uname); # or just one
Then turn it into an IP address and convert to its canonical name:
use Socket; # for AF_INET $address = gethostbyname($hostname) or die "Couldn't resolve $hostname : $!"; $hostname = gethostbyaddr($address, AF_INET) or die "Couldn't re-resolve $hostname : $!";
Sys::Hostname tries to be portable by using knowledge about your system to decide how best to find the hostname. It tries many different ways of getting the hostname, but several involve running other programs. This can lead to tainted data (see Recipe 19.1 ).
Once you have the name, though, you must consider that it might be missing a domain name. For instance, Sys::Hostname may return you
Copyright © 2002 O'Reilly & Associates. All rights reserved.