一个系统调用引发的血案! On 8/11/09, cnhack TNT <[email protected]> wrote: > "不知道有没有比较方面的用perl把域名转换为ip的简单代码?" > ----- > 楼主问的是 "比较方面(便)的用 perl 把域名转换成 ip 的简单代码", 所以用 ping, nslookup, dig, Socket > 模块,其他模块,其他方法不都能满足需求么 > 我在意的是你说 ”不要再误人子弟“, 我想来想去,还以为是用 ping 有什么不妥,但无论是用 ping 这种外部工具也好,还是你提及的 > gethostbyname 方法, > 都能满足楼主的要求,所以这个绝对不是误人子弟。 > Lin 没看清楚楼主问题而已:-) > > 2009/8/11 Lin <[email protected]> > >> 人家没有问 ping 了,而且用 ping 外部程序,还不如 nslookup 呢?:) >> >> 2009/8/11 cnhack TNT <[email protected]> >> >> 用 ping 这种简单的办法有什么不妥么? >>> >>> >>> 2009/8/11 Beckheng Lam <[email protected]> >>> >>> 同意,我以前的是这样的: >>>> >>>> 如何对IP地址进行域名反向查询一样. >>>> use Socket; >>>> @addresses = gethostbyname($name) or die "Can't resolve $name: $!n"; >>>> @addresses = map { inet_ntoa($_) } @addresses[4 .. $#addresses]; >>>> >>>> 反向查询 >>>> use Socket; >>>> $name = gethostbyaddr(inet_aton($address), AF_INET) or die "Can't >>>> resolve >>>> $address: $!n"; >>>> >>>> Lin(林兴陆) wrote: >>>> >>>> perl -e "print >>>> join('.',unpack('C4',(gethostbyname('www.google.com'))[4]));" >>>> ; >>>> >>>> 用unpack C4兼容性更好一点,W4似乎只在Windows下可解。 >>>> >>>> 2009/8/11 Lin <[email protected]> >>>> >>>>> 这都什么跟什么啊... 大家不要误人子弟了啦 >>>>> >>>>> C:\Users\Lin\Desktop>perl -e "print >>>>> join('.',unpack('W4',(gethostbyname('www.goo >>>>> gle.com'))[4]));"; >>>>> 66.249.89.147 >>>>> >>>>> %perl -e 'use Socket;my $packed_ip = gethostbyname(" >>>>> www.google.com");print >>>>> <http://www.google.com%22%29;print/>inet_ntoa($packed_ip);' ; >>>>> 64.233.189.147% >>>>> >>>>> 2009/8/10 Yuan Jiang <[email protected]> >>>>> >>>>>> http://blog.vetcafe.net/2009/07/perl_ping_dns.html >>>>>> >>>>>> 2009/8/10 cnhack TNT <[email protected]> >>>>>> >>>>>>> print $1 if qx/ping -c1 google.com/ =~ /\(([\d\.]+)\)/; >>>>>>> >>>>>>> 2009/8/10 imxae <[email protected]> >>>>>>> >>>>>>>> 在cpan 上搜来搜去,发现有的dns模块都太复杂了,不知道有没有比较方面的用perl把域名转换为ip的简单代码? >>>>>>> >>>>>>> >>>> >>>> >>>> >>>> >>>> -- >>>> Perl乐事 -- http://www.perlersh.org >>>> 我的博客 -- http://www.perlersh.org/blog.html >>>> >>>> >>>> >>>> >>> >> >>> > > > >
-- Sent from my mobile device 姜源 Yuan Jiang http://blog.vetcafe.net http://twitter.com/sleetdrop --~--~---------~--~----~------------~-------~--~----~ 您收到此信息是由于您订阅了 Google 论坛“PerlChina Mongers 讨论组”论坛。 要在此论坛发帖,请发电子邮件到 [email protected] 要退订此论坛,请发邮件至 [email protected] 更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛 -~----------~----~----~----~------~----~------~--~---
