perl获取机器ip

跟别人学习:http://blog.csdn.net/zhtsuc/article/details/3778517

我们在代码中常常需要获取本机或者远程主机的ip信息。所以必须动态的获取,perl中提供了相应的函数

#!/usr/bin/perl
use warnings;
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");
# print "remoteHost is $remoteHost\n";  # 输出的东西我不懂
my $remote_ip = inet_ntoa($remoteHost);
print "$remote_ip\n";

你可能感兴趣的:(IP,perl,host)