文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Perl->获取DNS地址

Perl->获取DNS地址

时间:2008-05-23  来源:lvDbing

  得到DNS地址的两个主要函数是Socket模块中的inet_aton()函数,用来保存DNS地址,然后使用inet_ntoa()函数把保存的地址转换成IP地址。   
  • inet_aton HOSTNAME

    Takes a string giving the name of a host, and translates that to an opaque string (if programming in C, struct in_addr). Takes arguments of both the 'rtfm.mit.edu' type and '18.181.0.24'. If the host name cannot be resolved, returns undef. For multi-homed hosts (hosts with more than one address), the first address found is returned.

    For portability do not assume that the result of inet_aton() is 32 bits wide, in other words, that it would contain only the IPv4 address in network order.

  • inet_ntoa IP_ADDRESS

    Takes a string (an opaque string as returned by inet_aton(), or a v-string representing the four octets of the IPv4 address in network order) and translates it into a string of the form 'd.d.d.d' where the 'd's are numbers less than 256 (the normal human-readable four dotted number notation for Internet addresses).

 

[[email protected] Perl]# cat -n rDNS.pl

     1 #!/usr/bin/perl -w

     2
     3 use Socket;
     4
     5 $SiteName = 'www.chinaunix.net';
     6
     7 $Address = inet_ntoa(inet_aton($SiteName));
     8
     9 print "The DNS address of www.chinaunix.net is $Address\n";
[[email protected] Perl]# perl rDNS.pl

The DNS address of www.chinaunix.net is 221.238.249.178
[[email protected] Perl]# ping www.chinaunix.net -c 3

PING www.chinaunix.net.fastcdn.com (221.238.249.178) 56(84) bytes of data.
64 bytes from 221.238.249.178: icmp_seq=0 ttl=52 time=45.9 ms
64 bytes from 221.238.249.178: icmp_seq=1 ttl=52 time=46.4 ms
64 bytes from 221.238.249.178: icmp_seq=2 ttl=52 time=46.2 ms

--- www.chinaunix.net.fastcdn.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2005ms
rtt min/avg/max/mdev = 45.901/46.194/46.456/0.227 ms, pipe 2

相关阅读 更多 +
排行榜 更多 +
坦克战争世界

坦克战争世界

模拟经营 下载
丛林反击战

丛林反击战

飞行射击 下载
几何飞行安卓版

几何飞行安卓版

飞行射击 下载