in reply to Extracting network information
Sys::Hostname is in core, the others you'll have to install from CPAN ...
Output:#!/usr/bin/perl use strict; use warnings; use Sys::Hostname; use Net::Address::IP::Local; use Net::Netmask; my $hostname = hostname; my $ip = Net::Address::IP::Local->public; my $netmask = Net::Netmask->new( $ip )->mask; print "hostname : $hostname\n"; print "IP : $ip\n"; print "Netmask : $netmask\n"; __END__
$ perl 1140691-2.pl hostname : localhost IP : 10.5.50.27 Netmask : 255.255.255.255 $
Update: if you want the internal IP address you can use gethostbyname() and Socket, which is in Core, and dump Net::Address::IP::Local:
See perlfaq9.use Sys::Hostname; use Socket; my $hostname = hostname; my $ip = inet_ntoa( scalar gethostbyname( $hostname ) );
|
|---|