#!/usr/bin/perl # IP Scanner 0.2 # By Feky # use IO::Socket; use Switch; # Check parameters if(@ARGV < 2){ print "IP Scanner 0.2\n Parameters: [ip] [port]\nOptions: -t [MILLISECONDS] Connection timeout (Default is 20). Use the \'-\' symbol to scan port ranges (0-500). Use the \',\' symbol to scan specific ports (21,25,80,22).\n"; exit 1; } # Set default options $timeout = 20; # Get options for($x = 0; $x <= scalar(@ARGV); ++$x){ switch($ARGV[$x]){ case "-t"{ $timeout = $ARGV[$x + 1]; } } } # Split IP addresses and ports @ip = split(/-/, $ARGV[0]); @sip = split(/\./, $ip[0]); if($ARGV[1] =~ /-/){ @port = split(/-/, $ARGV[1]); if($port[0] >= $port[-1]){ print "Port error.\n"; exit print "$port\n";; } @port = ($port[0]...$port[1]); } elsif($ARGV[1] =~ /,/){ @port = split(/,/, $ARGV[1]);; } # Check if a port is larger than 65535 for($x = 0; $x < scalar(@port); ++$x){ if($port[$x] > 65535){ print "Port error.\n"; } } # Scan print "Scanning...\n\n"; $x = 0; while(1){ $p = $port[$x]; $cip = join('.', @sip); IO::Socket::INET->new(PeerAddr=>$cip,PeerPort=>$p,proto=>'tcp',Timeout=>$timeout) and print "$cip:$p\n"; if($p == $port[-1]){ $sip[3] += "1"; $x = 0; } else { ++$p; } if($sip[3] > "255"){ $sip[2] += "1"; $sip[3] = "0"; } if($sip[2] > "255"){ $sip[1] += "1"; $sip[2] = "0"; } if($sip[1] > "255"){ $sip[0] += "1"; $sip[1] = "0"; } if($ip[1] =~ /$cip/){ print "\nScan completed.\n"; exit 1; } ++$x; } exit;