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";
相关文章
相关标签/搜索