Rajesh Dorairajan wrote:
Sorry. Missed out getting hostname.

use IO::Socket;
use Sys::Hostname;

$HOSTNAME = hostname();
$ip = inet_ntoa((gethostbyname($HOSTNAME))[4]);

Rajesh

# Either way this only works if /etc/hosts is populated:


use IO::Socket;
use Sys::Hostname;

$HOSTNAME = hostname("postfix.org");
$ip = inet_ntoa((gethostbyname($HOSTNAME))[4]); print "\n$ip\n";

# prints 192.168.1.69 regardless...

__END__

use IO::Socket;

"\n$ip\n";
$ip = Socket::inet_ntoa((gethostbyname(localhost))[4]); print "\n$ip\n";
$ip = Socket::inet_ntoa((gethostbyname(chasecreek))[4]); print "\n$ip\n";
$ip = Socket::inet_ntoa((gethostbyname(linksys))[4]); print "\n$ip\n";
$ip = Socket::inet_ntoa((gethostbyname(loghost))[4]); print "\n$ip\n";
$ip = Socket::inet_ntoa((gethostbyname(imac))[4]); print "\n$ip\n";

__END__

This only prints out what is
known in /etc/hosts -

127.0.0.1       localhost
192.168.1.69    insecurity.org chasecreek loghost
192.168.1.1     linksys fw
192.168.1.10    airlan  house
192.168.1.50    imac    angela

Otherwise it gives:
Usage: Socket::inet_ntoa(ip_address_sv) at IP line x.

error and exits immediately...

Cheers :)
--
_Sx_ http://youve-reached-the.endoftheinternet.org/ _____
     http://jaxpm.insecurity.org/
     http://cis4dl.insecurity.org/

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to