Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use Net::Ping;
- use IO::Select;
- use IO::Socket::INET;
- # IP address to scan
- print "Adresse IP : ";
- my $ip = <>;
- # First we will send a ping to make sure the scanned host is exist
- my $p = Net::Ping->new( "icmp", 1, 64 );
- if ( $p->ping($ip) ) {
- print "$ip Reponse au ping , Scan en cours ....\n";
- } else {
- print "$ip n a pas repond au ping \n ";
- exit 5;
- }
- # temps d'attente du "destination unreachable" packet
- my $icmp_timeout=2;
- # creation d'un icmp socket pour "destination unreachable" packets
- $icmp_sock = new IO::Socket::INET(Proto=>"icmp");
- $read_set = new IO::Select();
- $read_set->add($icmp_sock);
- # le buffer a envoyer en UDP
- my $buf="hello";
- # crée un socket udp pour l'ip et le port
- my $sock = new IO::Socket::INET(PeerAddr=>$ip,
- PeerPort=>161,
- Proto=>"udp"
- );
- #on envoye le buffer et ferme le socket
- $sock->send("$buf");
- close($sock);
- # attente de recevoir les packets
- ($new_readable) = IO::Select->select($read_set, undef, undef, $icmp_timeout);
- # arrivé des flags
- $icmp_arrived = 0;
- # pour tout les socket on a recu un packet (seulement - icmp_socket)
- foreach $socket (@$new_readable)
- {
- # si nous avons reussi ce qui est probable nosu avons "destination unreachable"
- if ($socket == $icmp_sock)
- {
- # met le flags et nettoye le buffer et sockets
- $icmp_arrived = 1;
- $icmp_sock->recv($buffer,50,0);
- }
- }
- if ( $icmp_arrived == 0 )
- {
- print "Le port $i est Ouvert sur $ip \n\n";
- }
- # Close the icmp sock
- close($icmp_sock);
- print "fin \n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement