Advertisement
fakessh

scanner ip with tftp upload file

Sep 26th, 2012
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.17 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use warnings;
  4. use Net::TFTP;
  5. use Net::Ping;
  6. use Data::Dumper;
  7. use FileHandle;
  8.  
  9. my $filename = $ARGV[0];
  10. my $lastlogping = $ARGV[1];
  11. usage() unless $filename;
  12. usage() unless $lastlogping;
  13. my $RESEAU;
  14. my $IP;
  15. my $tftp;
  16. my $port = 69;
  17. my %state;
  18. my $state;
  19. my $ip;
  20. my $ping;
  21. my $alive;
  22. my $sock;
  23. my %alive;
  24. my $pingerping;
  25. my $pingersocktftp;
  26. my $i;
  27. my $scalarlocaltime;
  28. my @map;
  29.  
  30. autoflush STDOUT 1;
  31.  
  32. for ($RESEAU = 2; $RESEAU <= 210; $RESEAU=$RESEAU+1)
  33. {
  34.     for ($IP = 2; $IP < 255; $IP = $IP+1)
  35.     {
  36.         if ("10.36.".$RESEAU.".".$IP)
  37.         {
  38.     $scalarlocaltime = scalar localtime;
  39.         my $p = Net::Ping->new('udp');
  40.         print "\nPinging host 10.36.$RESEAU.$IP\n";
  41.         if ($p->ping("10.36.$RESEAU.$IP"),1) {
  42.         ## If we didn't know it was up, spew that out now..
  43.     $pingerping = 1; $pingersocktftp = 0;
  44.         print "10.36.$RESEAU.$IP\twas up at ", scalar localtime, "\n" unless $state{$scalarlocaltime}{$pingerping}{$pingersocktftp}{10.36.$RESEAU.$IP};
  45.         ## Update the number of times we've seen it up
  46.          $state{$scalarlocaltime}{$pingerping}{$pingersocktftp}{10.36.$RESEAU.$IP}++;
  47.         ## And let STDOUT know about it, too.
  48.         ##print "alive $scalarlocaltime $pingerping $pingersocktftp 10.36.$RESEAU.$IP time";
  49.         }
  50.        
  51.         my$sock=IO::Socket::INET->new(
  52.            PeerAddr=>"10.36.$RESEAU.$IP",                                  
  53.            PeerPort=>"$port",        
  54.            Proto=>"tcp",
  55.            Timeout=>"5")
  56.      or warn "Cannot connect port 69 to 10.36.$RESEAU.$IP\n";
  57.      if (defined $sock) {
  58.      $pingersocktftp = 1;
  59.          }
  60.          
  61.  
  62.      ## Update the number of times we've seen it up
  63.      $state{$scalarlocaltime}{$pingerping}{$pingersocktftp}{10.36.$RESEAU.$IP}++;
  64.      ## And let STDOUT know about it, too.
  65.      ##print " alive ($pingerping $pingersocktftp 10.36.$RESEAU.$IP",scalar localtime;
  66.       $state{$scalarlocaltime}{$pingerping}{$pingersocktftp}{alive} = "10.36.$RESEAU.$IP";
  67.          ##make log map
  68.          @map = map { $_ => ${state{$_}{$_}{$_}{$_}}} %state;
  69.          
  70.       my $fh = FileHandle->new($lastlogping , "a");
  71.       if (defined($fh)){
  72.           print $fh " alive $scalarlocaltime $pingerping $pingersocktftp 10.36.$RESEAU.$IP time\n";
  73.           undef $fh;
  74.       }
  75.           if (defined ($sock )){
  76.           $tftp = Net::TFTP->new("10.36.$RESEAU.$IP", BlockSize => 1024)
  77.           or warn "cannot connect tftp serveur\n";
  78.       ## Update the number of times we've seen it up
  79.       $state{$scalarlocaltime}{$pingerping}{$pingersocktftp}{10.36.$RESEAU.$IP}++;
  80.       ## And let STDOUT know about it, too.
  81.       print "$state $scalarlocaltime  $pingerping  $pingersocktftp 10.36.$RESEAU.$IP transfert start";  
  82.           $tftp->binary;
  83.           $tftp->put($filename,$filename);
  84.           }
  85.  
  86.         }
  87.     }
  88. }
  89.  
  90. sub usage {
  91.   ## HERE documents are your friend for this kind of thing:
  92.   print <<"EO_USAGE";
  93. This program scans a C-class subnet and lists
  94. all machines, before with a udp ping after with a simple nmap scan
  95.  
  96. and last try to upload via a client tftp
  97.  
  98. You can also use this program to sort the output.
  99.  
  100. Usage:          perl $0 <file_to_transfer> <log_file_ping_ip>
  101. EO_USAGE
  102.   exit;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement