Advertisement
Sabriel

traceroat

Jun 25th, 2013
3,106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Per 1.08 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use IO::Socket;
  4. my $trace=$ARGV[0];
  5. my ($fh, $pid);
  6. my @res = ();
  7. eval {
  8.     local $SIG{ALRM} = sub{ kill 9, $pid; close $fh; die "Time is out" };
  9.     alarm 5;
  10.     eval {
  11.         $pid = open $fh, '-|', "tracert $trace" or die "Can't open file $!";
  12.         while ( my $str =  <$fh> ) {
  13.             push @res, $str;
  14.         }
  15.     };
  16.     alarm 0;
  17. };
  18. alarm 0;
  19. die $@ if $@ && $@ !~ /Time is out/;
  20.  
  21.  
  22. my $re=join(/ /,@res);
  23. my @resu = ();
  24. @resu=split(//,$re);
  25.  
  26. #my @re=grep /\([0-9]\{1,3\}\.\)\{3\}\[0-9]\{1,3\}\/,@resu;
  27. my @list = ($re) =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/g;
  28. #foreach(@list){print};
  29. #print @re;
  30. shift @list;
  31. foreach my $ip (@list){
  32.    for my $host ('whois.lacnic.net','whois.ripe.net','whois.arin.net','whois.apnic.net','whois.afrinic.net'){
  33.    my $port="43";
  34.    my $socket = IO::Socket::INET->new(PeerAddr => "$host", PeerPort => '43', Proto=>'tcp');
  35.     $socket->send("-a $ip\r\n");
  36.    my $last = 0;
  37.         while (<$socket>) {
  38.              if ($last = /(AS\d+)/) {
  39.                 print "$ip\t-> $1\n";
  40.                 last;
  41.             }
  42.         }
  43.         last if $last;
  44.     }
  45.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement