Perl获取机器hostname,ip(跨平台)

#! /usr/bin/perl -w

use strict;

use Socket;

use Sys::Hostname;

my $host = hostname;#output the host name;

print "Host name: ",$host,"/n";

my $name = gethostbyname($host);

my $ip_addr = inet_ntoa($name);

print $ip_addr,"/n";

print "get the ip of www.csdn.net/n";

my $remoteHost = gethostbyname("www.csdn.net");

my $remote_ip = inet_ntoa($remoteHost);

print $remote_ip,"/n";

你可能感兴趣的:(hostname,IP,职场,perl,休闲)