麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > Perl > 正文

Perl腳本檢測一個域名是否有效

2020-10-31 15:16:33
字體:
來源:轉載
供稿:網友

腳本功能:通過ICMP Ping或TCP/SYN探測指定的域名,探測前檢測域名是否有效。

file: check.host.pl#!/usr/bin/perluse strict;use Net::Ping;use Net::DNS;use Time::HiRes qw();$| = 1;my $DEFAULT_TIMEOUT = 2;my $PING_TIMEOUT = 2;my $DNS_TIMEOUT = 3;### 查詢域名是否有效sub queryDomain {  my $domain = shift();  my $query = '';  my $dns  = Net::DNS::Resolver->new(    tcp_timeout => $DNS_TIMEOUT, udp_timeout => $DNS_TIMEOUT, retry => 1  );  my @nameservers = qw/8.8.8.8 114.114.114.114/;  $dns->nameservers(@nameservers);  eval {	$query = $dns->search($domain,'A');  };  if ($@ or ! $query) {    my $err = $dns->errorstring ;    print "ERR: query $domain failed: $errn";    return if ($err =~ /NXDOMAIN/);  }  return 'OK';}### return nothing is FAILED, other is OKsub pingHost {  my $arg = shift();  return 1 if (ref $arg ne 'HASH');  my $p;  eval { $p = Net::Ping->new($arg->{'proto'},$DEFAULT_TIMEOUT,0) };  if ($@) { 	warn "ERR to create Net::Ping object: $@n";     return;  }	  $p->hires();  my ($host,$duration,$hip,$rep,$ret);  ### tcp/syn ping  if ($arg->{'proto'} eq "syn") {	$p->{port_num} = $arg->{'port'};	$p->ping($arg->{'host'},$PING_TIMEOUT);	if (($host,$duration,$hip) = $p->ack()) {	  printf("ACK Reply from $arg->{'host'}[%s] time=%.2f msn", $hip, $duration * 1000);      $ret = 'OK';    } else {      warn "SYN Request for $arg->{'host'} timed out.n";	}  }    ### icmp ping  else {    ($rep,$duration,$hip) = $p->ping($arg->{'host'},$PING_TIMEOUT);    if ($rep) {      printf("Echo Reply from $arg->{'host'}[%s] time=%.2f msn", $hip, $duration * 1000);      $ret = 'OK';    }	else {      warn "PING Request for $arg->{'host'} timed out.n";  	}  }  $p->close;  undef($p);  return $ret;}my $ARG = { proto => 'syn', port => 80 };my $host = $ARGV[0];my $proto = $ARGV[1];die "Usage: $0 [icmp]n" if (! $host);$ARG->{'host'} = $host;$ARG->{'proto'} = $proto if ($proto);my $code;if (&queryDomain($host) eq 'OK' and $code = &pingHost($ARG)) {  print "$host is online !n";}else {  print "$host is DOWN !n";}

測試例子:

# ./check.host.pl 2013.VeVB.COmERR: query 2013.VeVB.COm failed: NXDOMAIN2013.VeVB.COm is DOWN !# ./check.host.pl www.companysz.comACK Reply from www.companysz.com[173.255.214.254] time=307.04 mswww.companysz.com is online !# ./check.host.pl VeVB.COm icmpEcho Reply from VeVB.COm[173.255.214.254] time=205.61 msVeVB.COm is online !# ./check.host.pl chinagfw.com icmpPING Request for chinagfw.com timed out.chinagfw.com is DOWN !

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久草在线资源观看 | 国产精品久久久久久影视 | 91成人天堂久久成人 | av在线一区二区三区四区 | 欧美一级精品片在线看 | 宅男噜噜噜66国产在线观看 | 97伦理| 欧美一级一区二区三区 | 777sesese| 亚洲人成网在线观看 | 91久久夜色精品国产网站 | 国产亚洲精品综合一区91 | 国产成人精品日本亚洲语音 | 护士xxxx | 免费一区在线 | 在线成人免费网站 | 黄视频免费在线 | 日韩精品羞羞答答 | 一区二区三区在线观看国产 | 久草视频国产在线 | 欧美一级三级在线观看 | 国产精品亚洲精品久久 | 久久精品视频16 | 在线免费黄色网 | 精品人伦一区二区三区蜜桃网站 | 国产手机在线视频 | www.99久久久 | 亚洲成人免费网站 | 亚洲国产一区二区三区 | 一本大道av| 久久狂草 | 亚洲午夜1000理论片aa | 亚洲精品a级 | 亚洲成人激情在线 | 国产精品久久久久久久久岛 | 亚洲欧美日韩久久精品第一区 | 国产精品久久久毛片 | 在线成人免费av | 国产美女视频一区二区三区 | 毛片视频免费观看 | 欧美一级特黄aaaaaa在线看首页 |