Chinaunix首页 | 论坛 | 博客
  • 博客访问: 203987
  • 博文数量: 39
  • 博客积分: 1057
  • 博客等级: 准尉
  • 技术积分: 926
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-27 20:13
文章分类

全部博文(39)

文章存档

2012年(24)

2011年(15)

分类: Python/Ruby

2012-03-17 14:46:41


点击(此处)折叠或打开

  1. #!/usr/bin/perl -w
  2. # name:Ping.pl
  3. # 以syn协议检测目标,
  4. # 来源: Lover的工具小屋
  5. # author: Lover

  6. use strict;
  7. use Net::Ping;
  8. my @hosts = qw(xx100.my4399.com xx10.my4399.com);

  9. =pod
  10. my ($host,$rtt,$ip);
  11. my $p = Net::Ping->new('syn');
  12.    $p->port_number(80);

  13. # 这里演示syn的用法
  14. foreach $host (@hosts){
  15.         # 对方收到俺的syn之后进入syn_recv状态,在等待俺给回一个ack
  16.         $p->ping($host);
  17. }
  18. # 这里给对方发送了一个ack包,以结束对方的syn_recv的状态,防止将没有对syn攻击进行防范的主机拖进很难堪的境地
  19. while (($host,$rtt,$ip) = $p->ack) {
  20.         print("HOST: $host [$ip] ACKed in $rtt seconds.\n");
  21. }
  22. $p->close();
  23. =cut

  24. # 用icmp协议来检测主机
  25. my $p = Net::Ping->new('icmp');
  26. my ($host,$ret,$duration,$ip);
  27. # 显示开启响应时间处理函数,以微秒为单位
  28.    $p->hires(1);
  29. foreach $host (@hosts){
  30.         ($ret,$duration,$ip) = $p->ping($host,1);
  31.         if ($ret){
  32.                 printf("$host [$ip] is alive (packet return time: %0.2f ms)\n",1000*$duration);
  33.         }else{
  34.                 printf("$host [$ip] is down\n");
  35.         }
  36. }

  37. $p->close();

阅读(2426) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~