happy_boy 发表于 2018-8-31 12:37:09

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

页: [1]
查看完整版本: Perl获取机器hostname,ip(跨平台)