ItzStaze

ntpscan.pl

Mar 26th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use Net::IP;
  4. use Net::Ping;
  5. use IO::Select;
  6. use IO::Socket::INET;
  7. use Term::ANSIColor;
  8. use vars qw( $PROG );
  9. ( $PROG = $0 ) =~ s/^.*[\/\\]//;
  10.  
  11. if ( @ARGV == 0 ) {
  12. print "Utilisation : perl $PROG.pl [Start Ip Range ] [End IP Range] [Port (123 for NTP & 161 for SNMP) ] [Threads] [Timeout] [Outpout .txt]\n";
  13. exit;
  14. }
  15. my $threads = $ARGV[3];
  16. my @ip_team = ();
  17. $|= 1;
  18. my $ip = new Net::IP ("$ARGV[0] - $ARGV[1]") or die "Error Range IP .". Net::IP::Error() ."\n";
  19.  
  20.  
  21.  
  22. while ($ip) {
  23. push @ip_team, $ip++ ->ip();
  24. if ( $threads == @ip_team ) { Scan(@ip_team); @ip_team = () }
  25. }
  26. Scan(@ip_team);
  27.  
  28.  
  29. sub Scan
  30. {
  31. my @Pids;
  32.  
  33. foreach my $ip (@_)
  34. {
  35. my $pid = fork();
  36. die "Fork Error ! $!\n" unless defined $pid;
  37.  
  38. if (0 == $pid)
  39. {
  40.  
  41.  
  42. alarm 1;
  43.  
  44.  
  45.  
  46. my $icmp_timeout=2;
  47.  
  48. $icmp_sock = new IO::Socket::INET(Proto=>"icmp");
  49. $read_set = new IO::Select();
  50. $read_set->add($icmp_sock);
  51.  
  52.  
  53. my $buf="hello";
  54.  
  55.  
  56.  
  57.  
  58.  
  59. my $sock = new IO::Socket::INET(PeerAddr=>$ip,
  60. PeerPort=>$ARGV[2],
  61. Proto=>"udp",
  62. Timeout => $ARGV[4]);
  63.  
  64. $sock->send("$buf");
  65. close($sock);
  66.  
  67.  
  68. ($new_readable) = IO::Select->select($read_set, undef, undef, $icmp_timeout);
  69.  
  70. $icmp_arrived = 0;
  71.  
  72. foreach $socket (@$new_readable)
  73. {
  74.  
  75. if ($socket == $icmp_sock)
  76. {
  77.  
  78. $icmp_arrived = 1;
  79. $icmp_sock->recv($buffer,50,0);
  80. }
  81. }
  82.  
  83.  
  84.  
  85.  
  86.  
  87. open (MYFILE, ">>$ARGV[5]");
  88. if ( $icmp_arrived == 0 ) {
  89. print MYFILE "$ip\n";
  90. print "IP FOUND : $ip\n";
  91. close (MYFILE);}
  92.  
  93. exit
  94. }
  95. else
  96. {
  97. push @Pids, $pid
  98. }
  99. }
  100.  
  101. foreach my $pid (@Pids) { waitpid($pid, 0) }
  102. }
Add Comment
Please, Sign In to add comment