Advertisement
Gentoo7

portscanner

Jul 19th, 2016
28,553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.86 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. # TCP Port scanner
  4.  
  5. use IO::Socket;
  6.  
  7. # flush the print buffer immediately
  8. $| = 1;
  9.  
  10. # Take input from user - hostname, start port , end port
  11. print "Enter Target/hostname : ";
  12.  
  13. # Need to chop off the newline character from the input
  14. chop ($target = <stdin>);
  15. print "Start Port : ";
  16. chop ($start_port = <stdin>);
  17. print "End Port : ";
  18. chop ($end_port = <stdin>);
  19.  
  20. # start the scanning loop
  21. foreach ($port = $start_port ; $port <= $end_port ; $port++)
  22. {
  23.     #\r will refresh the line
  24.     print "\rScanning port $port";
  25.      
  26.     #Connect to port number
  27.     $socket = IO::Socket::INET->new(PeerAddr => $target , PeerPort => $port , Proto => 'tcp' , Timeout => 1);
  28.      
  29.     #Check connection
  30.     if( $socket )
  31.     {
  32.         print "\r = Port $port is open.\n" ;
  33.     }
  34.     else
  35.     {
  36.         #Port is closed, nothing to print
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement