Guest User

parse xml dvrs

a guest
Jan 25th, 2013
239
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl
  2. # Read from: nmap -n -iL ips -p80 -sT -Pn --script getdvrcfg
  3. # --min-rate=5000 -m 256 -v --min-hostgroup=1000 --script getdvrcfg -oA getDVR
  4. use Nmap::Parser;
  5. use Data::Dumper;
  6. use JSON::XS;
  7. use Geo::IP;
  8. use strict;
  9.  
  10. my $gi = Geo::IP->open("./GeoLiteCity.dat", GEOIP_STANDARD);
  11. my $xmlfile = $ARGV[0];
  12. my $all;
  13.  
  14. print "# Reading from NMAP XML File '$xmlfile'.\n";
  15. my $i=0;
  16.  
  17. my $np = new Nmap::Parser;
  18. $np->parsefile("$xmlfile"); # $name
  19. my $session = $np->get_session();
  20. my $nmapv   = $session->nmap_version();
  21. my $xmlv    = $session->xml_version();
  22. for my $host ($np->all_hosts()) {
  23.    my $os_sig = $host->os_sig();
  24.    my $ipv4  = $host->ipv4_addr();
  25.    my $hostn  = $host->hostname();
  26.    for my $tcp ($host->tcp_ports()){
  27.                 my $service = $host->tcp_service($tcp);
  28.         my $exinf = $service->extrainfo();
  29.         if ($service->scripts('getdvrcfg')) {
  30.                 my $htmlindex = $service->scripts('getdvrcfg')->{output};
  31.                 if ($htmlindex =~ /_NAME=/) {
  32.                         $i++;
  33.                         my $record = $gi->record_by_addr($ipv4);
  34.                         push @$all, {
  35.                                  ip => $ipv4,
  36.                          lat => $record->latitude,
  37.                          lon => $record->longitude,
  38.                          city => $record->city || $record->country_name
  39.                        };
  40.                          }
  41.         }
  42.  
  43.    }
  44. }
  45.  
  46. open J, ">cams.json" or die "No puedo abrir cams.json\n";
  47. print J "var cams=";
  48. print J encode_json( $all );
  49. close J;
  50. print "Records: $i\n";
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×