Changeset 96 for trunk/klask


Ignore:
Timestamp:
Mar 30, 2011, 6:16:42 PM (13 years ago)
Author:
g7moreau
Message:
  • Cleanup code
  • Give interface when updatedb
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r92 r96  
    159159   my $fh     = new FileHandle;
    160160   my $result = '';
    161    open $fh, q{-|}, "$cmd" or die "Can't exec $cmd\n";
     161   open $fh, q{-|}, "LANG=C $cmd" or die "Can't exec $cmd\n";
    162162   $result .= <$fh>;
    163163   close $fh;
     
    179179      );
    180180
    181 #   my $cmdarping  = `arping -c 1 -w 1 -rR $param 2>/dev/null`;
    182 #   if ( not $param_ip_or_host =~ m/^\d+ \. \d+ \. \d+ \. \d+$/xms ) {
    183 #      $param_ip_or_host =~ s/ \. .* //xms;
    184 #      }
    185 
    186    #my $dns_resolver =  Net::DNS::Resolver->new;
    187    #my $dns_answer = $dns_resolver->query($param_ip_or_host);
    188    #if ($dns_answer) {
    189    #   $ret{ipv4_address} = $dns_answer->address;
    190    #   }
    191 
    192181   # perl -MSocket -E 'say inet_ntoa(scalar gethostbyname("tech7meylan.hmg.inpg.fr"))'
    193182   my $packed_ip = scalar gethostbyname($param_ip_or_host);
     
    197186   # perl -MSocket -E 'say scalar gethostbyaddr(inet_aton("194.254.66.240"), AF_INET)'
    198187   my $hostname_fq = scalar gethostbyaddr($packed_ip, AF_INET);
    199 #   return %ret if not defined $hostname_fq;
    200188   $ret{hostname_fq} = $hostname_fq if defined $hostname_fq;
    201 
    202 #print "DEBUG : $param_ip_or_host --  $ret{ipv4_address} --   $hostname_fq \n";
    203 
    204    # controler que arpwatch tourne !
    205    # resultat de la commande arpwatch
    206    # /var/lib/arpwatch/arp.dat
    207    # 0:13:d3:e1:92:d0        192.168.24.109  1163681980      theo8sv109
    208    # my $cmd = "grep  -e '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/arp.dat | sort +2rn | head -1";
    209    # my $cmd = "grep  -he '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/*.dat | sort +2rn | head -1";
    210 
    211 ### BOGUE ICI
    212 ### FAIRE LE GREP SUR L'IP !
    213189
    214190   # my $cmd = q{grep  -he '\b} . $param_ip_or_host . q{\b' } . "/var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1";
     
    217193   my ($arp, $ip, $timestamp, $host) = split m/ \s+ /xms, $cmd_arpwatch;
    218194
    219 #   $ret{ipv4_address} = $ip        if $ip;
    220195   $ret{mac_address}  = $arp       if $arp;
    221196   $ret{timestamp}    = $timestamp if $timestamp;
     
    223198   my $nowtimestamp = time;
    224199
    225    if ( $type eq 'fast' and ( not defined $timestamp or $timestamp < ( $nowtimestamp - 1.1 * 3600 ) ) ) {
     200   if ( $type eq 'fast' and ( not defined $timestamp or $timestamp < ( $nowtimestamp - 45 * 60 ) ) ) { # 45 min
    226201      $ret{mac_address} = 'unknow';
    227202      return %ret;
     
    236211      }
    237212
    238    # resultat de la commande host si le parametre est ip
    239    # 250.66.254.194.in-addr.arpa domain name pointer legihp2100.hmg.inpg.fr.
    240 #   my $cmd_host = shell_command "host $param_ip_or_host";
    241 #   if ( $cmd_host =~ m/domain \s name \s pointer \s (\S+) \.$/xms ) {
    242 #      $ret{hostname_fq} = $1;
    243 #      }
    244 
    245    # resultat de la commande host si parametre est hostname
    246    # tech7meylan.hmg.inpg.fr has address 194.254.66.240
    247 #   if ( $cmd_host =~ m/(\S*) \s has \s address \s ( $RE_IPv4_ADDRESS )$/xms ) {
    248 #      ( $ret{hostname_fq}, $ret{ipv4_address} ) = ($1, $2);
    249 #      }
    250 
    251    # Connerie !
    252    # Inverse les IP !!
    253    # if ( $cmd_host =~ m/ \b ( $RE_IPv4_ADDRESS ) \. in-addr \. arpa \s/xms ) {
    254    #    $ret{ipv4_address} = $1;
    255    #    }
    256    #$ret{hostname_fq}  = $param_ip_or_host if not defined $1 and $ret{hostname_fq} eq 'unknow';
    257 
     213   # Normalize MAC Address
    258214   if ($ret{mac_address} ne 'unknow') {
    259215      my @paquets = ();
     
    738694
    739695         printf "\rComputer scanned: %4i/%i (%2i%%)",  $i,                 $number_of_computer, $total_percent;
    740 #         printf ", Computer detected: %4i/%i (%2i%%)", $detected_computer, $size_of_database,   int(($detected_computer*100)/$size_of_database);
    741696         printf ', detected: %4i/%i (%2i%%)', $detected_computer, $size_of_database,   int(($detected_computer*100)/$size_of_database);
    742697         printf ' [Time: %02i:%02i / %02i:%02i]', int($localtime/60), $localtime % 60, int($time_elapse/60), $time_elapse % 60;
    743 #         printf '  [%02i:%02i/%02i:%02i]', int($localtime/60), $localtime % 60, int($time_elapse/60), $time_elapse % 60;
    744          printf ' %-14s', $one_computer;
    745 
    746          my %resol_arp = resolve_ip_arp_host($one_computer,$current_interface);
     698         printf ' %-8s %-14s', $current_interface, $one_computer;
     699
     700         my %resol_arp = resolve_ip_arp_host($one_computer, $current_interface);
    747701
    748702         # do not search on router connection (why ?)
Note: See TracChangeset for help on using the changeset viewer.