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";

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章