Perl获取机器hostname,ip(跨平台)

前端之家收集整理的这篇文章主要介绍了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";

猜你在找的Perl相关文章