Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use IO::Socket;
- my $trace=$ARGV[0];
- my ($fh, $pid);
- my @res = ();
- eval {
- local $SIG{ALRM} = sub{ kill 9, $pid; close $fh; die "Time is out" };
- alarm 5;
- eval {
- $pid = open $fh, '-|', "tracert $trace" or die "Can't open file $!";
- while ( my $str = <$fh> ) {
- push @res, $str;
- }
- };
- alarm 0;
- };
- alarm 0;
- die $@ if $@ && $@ !~ /Time is out/;
- my $re=join(/ /,@res);
- my @resu = ();
- @resu=split(//,$re);
- #my @re=grep /\([0-9]\{1,3\}\.\)\{3\}\[0-9]\{1,3\}\/,@resu;
- my @list = ($re) =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/g;
- #foreach(@list){print};
- #print @re;
- shift @list;
- foreach my $ip (@list){
- for my $host ('whois.lacnic.net','whois.ripe.net','whois.arin.net','whois.apnic.net','whois.afrinic.net'){
- my $port="43";
- my $socket = IO::Socket::INET->new(PeerAddr => "$host", PeerPort => '43', Proto=>'tcp');
- $socket->send("-a $ip\r\n");
- my $last = 0;
- while (<$socket>) {
- if ($last = /(AS\d+)/) {
- print "$ip\t-> $1\n";
- last;
- }
- }
- last if $last;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement