Advertisement
Guest User

Untitled

a guest
Jun 17th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.69 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use Net::Ping;
  4. use IO::Select;
  5. use IO::Socket::INET;
  6.  
  7. # IP address to scan
  8.  
  9. print "Adresse IP : ";
  10. my $ip = <>;
  11.  
  12. # First we will send a ping to make sure the scanned host is exist
  13. my $p = Net::Ping->new( "icmp", 1, 64 );
  14. if ( $p->ping($ip) ) {
  15.  print "$ip Reponse au ping , Scan en cours  ....\n";
  16. } else {
  17.  print "$ip n a pas repond au ping \n ";
  18. exit 5;
  19. }
  20.  
  21.                                     # temps d'attente du  "destination unreachable" packet
  22. my $icmp_timeout=2;
  23. # creation d'un icmp socket pour  "destination unreachable" packets
  24. $icmp_sock = new IO::Socket::INET(Proto=>"icmp");
  25. $read_set = new IO::Select();
  26. $read_set->add($icmp_sock);
  27.  
  28. # le buffer a envoyer en UDP
  29. my $buf="hello";
  30.  
  31.  
  32.  
  33.  
  34.       # crée un socket udp pour l'ip et le port
  35.     my $sock = new IO::Socket::INET(PeerAddr=>$ip,
  36.     PeerPort=>161,
  37.     Proto=>"udp"
  38.     );
  39.      #on envoye le buffer et ferme le socket
  40.     $sock->send("$buf");
  41.     close($sock);
  42.  
  43.       # attente de recevoir les packets
  44.     ($new_readable) = IO::Select->select($read_set, undef, undef, $icmp_timeout);
  45.       # arrivé des flags
  46.     $icmp_arrived = 0;
  47.       # pour tout les socket on a recu un packet (seulement - icmp_socket)
  48.     foreach $socket (@$new_readable)
  49.     {
  50.            # si nous avons reussi ce qui est probable nosu avons  "destination unreachable"
  51.          if ($socket == $icmp_sock)
  52.          {
  53.                 # met le flags et nettoye le buffer et sockets
  54.               $icmp_arrived = 1;
  55.               $icmp_sock->recv($buffer,50,0);
  56.          }
  57.     }
  58.     if ( $icmp_arrived == 0 )
  59.     {
  60.          print "Le port $i est Ouvert sur $ip \n\n";
  61.     }
  62.  
  63. # Close the icmp sock
  64. close($icmp_sock);
  65. print "fin  \n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement