Share Pastebin
Guest
Public paste!

epixoip

By: a guest | Aug 9th, 2009 | Syntax: Perl | Size: 1.50 KB | Hits: 61 | Expires: Never
Copy text to clipboard
  1. #!/usr/bin/perl
  2. # Tue Apr  3 16:42:08 PDT 2007 by epixoip <epixoip@hush.com>
  3. # synping - a tcp syn ping utility
  4.  
  5. use Net::Ping;
  6. use Time::HiRes;
  7. use Getopt::Std;
  8.  
  9. my %options = ();
  10. getopts("c:i:t:T",\%options);
  11. our $host = $ARGV[0];
  12. our $port = $ARGV[1];
  13. our $seq = 0;
  14.  
  15. &usage unless defined($port);
  16.  
  17. sub usage {
  18.         print "SYN Ping Utility - by epixoip <epixoip\@hush.com>\n";
  19.         print "Usage:\t$0 [-citT] <host> <port>\n";
  20.         print "\t-c\tStop after \$foo iterations\n";
  21.         print "\t-i\tWait \$foo seconds between iterations\n";
  22.         print "\t-t\tSet TTL to \$foo\n";
  23.         print "\t-T\tTimestamp output\n\n";
  24.         exit(1);
  25. }
  26.  
  27. $p = Net::Ping->new("syn", $options{t});
  28. $p->hires();
  29. $p->{port_num} = $port;
  30. while (1) {
  31.         $p->ping($host);
  32.         if (($hostn,$rtt,$ip) = $p->ack) {
  33.                 print "[", localtime(time), "] " if defined($options{T});
  34.                 printf("ack from $host ($ip) port=$port seq=$seq time=%.2f ms\n", $rtt * 1000);
  35.         } else {
  36.                 my $reason = $p->nack($host);
  37.                 print "[", localtime(time), "] " if defined($options{T});
  38.                 print "seq $seq: no reply from $host: $reason\n";
  39.         }
  40.         if (defined($options{c})) {
  41.                 if ($seq == $options{c} - 1) {
  42.                         exit(0);
  43.                 }
  44.         }
  45.         $seq++;
  46.         if (defined($options{i})) {
  47.                 sleep($options{i});
  48.         } else {
  49.                 sleep(1);
  50.         }
  51. }