跟別人學習: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";