Advertisement
Codefox

Untitled

Nov 2nd, 2013
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. # IP Scanner
  3. # By Feky
  4. #
  5. use IO::Socket;
  6.  
  7. # Check if parameters are set
  8. if(@ARGV != 4){
  9. print "Parameters: [min ip] [max ip] [min port] [max port]\n";
  10. exit 1;
  11. }
  12. # Check for port errors
  13. if(($ARGV[2] > $ARGV[3]) || ($ARGV[2] > 65535) || ($ARGV[3] > 65535)){
  14. print "Port error.\n";
  15. exit 1;
  16. }
  17.  
  18. # Check for IP address errors
  19. @sip = split(/\./, $ARGV[0]);
  20. @eip = split(/\./, $ARGV[1]);
  21. for($x = 0; $x < 4; ++$x){
  22. if(($sip[$x] > 255) || ($eip[$x] > 255)){
  23. print "IP address error.\n";
  24. exit 1;
  25. }
  26. }
  27. $p = 0;
  28. print "Scanning...\n\n";
  29. while(1){
  30. $cip = join('.', @sip);
  31. IO::Socket::INET->new(PeerAddr=>($cip),PeerPort=>$p,proto=>'tcp',Timeout=>1) and print "$cip:$p\n";
  32. if($p == $ARGV[3]){
  33. $sip[3] += "1";
  34. $p = $ARGV[2];
  35. } else {
  36. ++$p;
  37. }
  38. if($sip[3] > "255"){
  39. $sip[2] += "1";
  40. $sip[3] = "0";
  41. }
  42. if($sip[2] > "255"){
  43. $sip[1] += "1";
  44. $sip[2] = "0";
  45. }
  46. if($sip[1] > "255"){
  47. $sip[0] += "1";
  48. $sip[1] = "0";
  49. }
  50. if($ARGV[1] =~ /$cip/){
  51. print "\nScan completed.\n";
  52. exit 1;
  53. }
  54. }
  55. exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement