Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- # IP Scanner
- # By Feky
- #
- use IO::Socket;
- # Check if parameters are set
- if(@ARGV != 4){
- print "Parameters: [min ip] [max ip] [min port] [max port]\n";
- exit 1;
- }
- # Check for port errors
- if(($ARGV[2] > $ARGV[3]) || ($ARGV[2] > 65535) || ($ARGV[3] > 65535)){
- print "Port error.\n";
- exit 1;
- }
- # Check for IP address errors
- @sip = split(/\./, $ARGV[0]);
- @eip = split(/\./, $ARGV[1]);
- for($x = 0; $x < 4; ++$x){
- if(($sip[$x] > 255) || ($eip[$x] > 255)){
- print "IP address error.\n";
- exit 1;
- }
- }
- $p = 0;
- print "Scanning...\n\n";
- while(1){
- $cip = join('.', @sip);
- IO::Socket::INET->new(PeerAddr=>($cip),PeerPort=>$p,proto=>'tcp',Timeout=>1) and print "$cip:$p\n";
- if($p == $ARGV[3]){
- $sip[3] += "1";
- $p = $ARGV[2];
- } 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($ARGV[1] =~ /$cip/){
- print "\nScan completed.\n";
- exit 1;
- }
- }
- exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement