跟别人学习:
我们在代码中常常需要获取本机或者远程主机的ip信息。所以必须动态的获取,perl中提供了相应的函数
#!/usr/bin/perluse warnings;use strict;use Socket;use Sys::Hostname;my $host = hostname; # output the host nameprint "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";