Changeset 68


Ignore:
Timestamp:
Nov 2, 2010, 11:24:46 AM (13 years ago)
Author:
g7moreau
Message:
  • Add new switch model
  • Add search option in help
  • Better DNS search
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r67 r68  
    1818use NetAddr::IP;
    1919use Getopt::Long;
     20use Socket;
    2021
    2122# apt-get install snmp fping libnet-cidr-lite-perl libnet-netmask-perl libnet-snmp-perl libnetaddr-ip-perl libyaml-perl
    22 # libcrypt-des-perl libcrypt-hcesha-perl libdigest-hmac-perl
     23# libcrypt-des-perl libcrypt-hcesha-perl libdigest-hmac-perl 
    2324# arping fping bind9-host arpwatch
    2425
     
    7980   J4120A => { model => 'HP1600M',    match => 'HP J4120A ProCurve Switch 1600M' },
    8081   J9029A => { model => 'HP1800-8G',  match => 'PROCURVE J9029A'                 },
     82   J9449A => { model => 'HP1810-8G',  match => 'HP ProCurve 1810G - 8 GE'        },
    8183   J4093A => { model => 'HP2424M',    match => 'HP J4093A ProCurve Switch 2424M' },
    8284   J4813A => { model => 'HP2524',     match => 'HP J4813A ProCurve Switch 2524'  },
     
    9294
    9395Readonly my %OID_NUMBER => (
    94    sysDescription => '1.3.6.1.2.1.1.1.0',
    95    sysName        => '1.3.6.1.2.1.1.5.0',
    96    sysContact     => '1.3.6.1.2.1.1.4.0',
    97    sysLocation    => '1.3.6.1.2.1.1.6.0',
    98    ifMtu          => '1.3.6.1.2.1.2.2.1.4',
    99    ifSpeed        => '1.3.6.1.2.1.2.2.1.5',
     96   sysDescription  => '1.3.6.1.2.1.1.1.0',
     97   sysName         => '1.3.6.1.2.1.1.5.0',
     98   sysContact      => '1.3.6.1.2.1.1.4.0',
     99   sysLocation     => '1.3.6.1.2.1.1.6.0',
    100100   );
    101101
     
    139139# fast ping dont l'objectif est de remplir la table arp de la machine
    140140sub fastping {
    141    system "fping -c 1 @_ >/dev/null 2>&1";
     141   # Launch this command without waiting...
     142   system "fping -c 1 @_ >/dev/null 2>&1 &";
    142143   return;
    143144   }
     
    169170
    170171#   my $cmdarping  = `arping -c 1 -w 1 -rR $param 2>/dev/null`;
    171    if ( not $param_ip_or_host =~ m/^\d+ \. \d+ \. \d+ \. \d+$/xms ) {
    172       $param_ip_or_host =~ s/ \. .* //xms;
    173       }
     172#   if ( not $param_ip_or_host =~ m/^\d+ \. \d+ \. \d+ \. \d+$/xms ) {
     173#      $param_ip_or_host =~ s/ \. .* //xms;
     174#      }
     175
     176   #my $dns_resolver =  Net::DNS::Resolver->new;
     177   #my $dns_answer = $dns_resolver->query($param_ip_or_host);
     178   #if ($dns_answer) {
     179   #   $ret{ipv4_address} = $dns_answer->address;
     180   #   }
     181
     182   # perl -MSocket -E 'say inet_ntoa(scalar gethostbyname("tech7meylan.hmg.inpg.fr"))'
     183   my $packed_ip = scalar gethostbyname($param_ip_or_host);
     184   return %ret if not defined $packed_ip;
     185   $ret{ipv4_address} = inet_ntoa($packed_ip);
     186
     187   # perl -MSocket -E 'say scalar gethostbyaddr(inet_aton("194.254.66.240"), AF_INET)'
     188   my $hostname_fq = scalar gethostbyaddr($packed_ip, AF_INET);
     189#   return %ret if not defined $hostname_fq;
     190   $ret{hostname_fq} = $hostname_fq if defined $hostname_fq;
     191
     192#print "DEBUG : $param_ip_or_host --  $ret{ipv4_address} --   $hostname_fq \n";
    174193
    175194   # controler que arpwatch tourne !
     
    179198   # my $cmd = "grep  -e '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/arp.dat | sort +2rn | head -1";
    180199   # my $cmd = "grep  -he '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/*.dat | sort +2rn | head -1";
    181    my $cmd = q{grep  -he '\b} . $param_ip_or_host . q{\b' } . "/var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1";
     200
     201### BOGUE ICI
     202### FAIRE LE GREP SUR L'IP !
     203
     204   # my $cmd = q{grep  -he '\b} . $param_ip_or_host . q{\b' } . "/var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1";
     205   my $cmd = q{grep  -he '\b} . $ret{ipv4_address} . q{\b' } . "/var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1";
    182206   my $cmd_arpwatch = shell_command $cmd;
    183207   my ($arp, $ip, $timestamp, $host) = split m/ \s+ /xms, $cmd_arpwatch;
    184208
    185    $ret{ipv4_address} = $ip        if $ip;
     209#   $ret{ipv4_address} = $ip        if $ip;
    186210   $ret{mac_address}  = $arp       if $arp;
    187211   $ret{timestamp}    = $timestamp if $timestamp;
     
    204228   # resultat de la commande host si le parametre est ip
    205229   # 250.66.254.194.in-addr.arpa domain name pointer legihp2100.hmg.inpg.fr.
    206    my $cmd_host = shell_command "host $param_ip_or_host";
    207    if ( $cmd_host =~ m/domain \s name \s pointer \s (\S+) \.$/xms ) {
    208       $ret{hostname_fq} = $1;
    209       }
     230#   my $cmd_host = shell_command "host $param_ip_or_host";
     231#   if ( $cmd_host =~ m/domain \s name \s pointer \s (\S+) \.$/xms ) {
     232#      $ret{hostname_fq} = $1;
     233#      }
    210234
    211235   # resultat de la commande host si parametre est hostname
    212236   # tech7meylan.hmg.inpg.fr has address 194.254.66.240
    213    if ( $cmd_host =~ m/(\S*) \s has \s address \s ( $RE_IPv4_ADDRESS )$/xms ) {
    214       ( $ret{hostname_fq}, $ret{ipv4_address} ) = ($1, $2);
    215       }
     237#   if ( $cmd_host =~ m/(\S*) \s has \s address \s ( $RE_IPv4_ADDRESS )$/xms ) {
     238#      ( $ret{hostname_fq}, $ret{ipv4_address} ) = ($1, $2);
     239#      }
    216240
    217241   # Connerie !
     
    416440         my $swport = $result->{$research};
    417441
     442#print "DEBUG $arp  $swport --  $sw->{hostname} \n";
     443         if ( $sw->{hostname} eq 'sw10-batE1-3s.hmg.priv' and $swport == 19 ) { $swport = 20; print "DEBUG $swport --  $sw->{hostname} \n";}
     444         if ( $sw->{hostname} eq 'sw8-batE1-3s.hmg.priv'  and $swport == 23 ) { $swport = 24; print "DEBUG $swport --  $sw->{hostname} \n";}
     445#         if ( $sw->{hostname} eq 'sw10-batE1-3s.hmg.priv' ) {  print "DEBUG $swport --  $sw->{hostname} \n";}
     446#         if ( $sw->{hostname} eq 'sw8-batE1-3s.hmg.priv'  ) {  print "DEBUG $swport --  $sw->{hostname} \n";}
     447
    418448         $ret->{$sw->{hostname}} = {};
    419449         $ret->{$sw->{hostname}}{hostname}    = $sw->{hostname};
     
    562592 klask searchdb computer
    563593 klask search   computer
     594 klask search-mac-on-switch switch mac_addr
    564595
    565596 klask enable  switch port
     
    12321263
    12331264      $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address}); # find port on all switch
     1265#my @l = ();
     1266#for my $c  ( keys %{$where{$resol_arp{ipv4_address}}} ) {
     1267#push @l, "$c -+ "; #$where{$resol_arp{ipv4_address}}->{$c}{hostname};
     1268#}
     1269#print "DEBUG  $one_computer $resol_arp{ipv4_address} $resol_arp{mac_address} --- @l\n";
    12341270
    12351271      $db_switch_ip_hostname{$resol_arp{ipv4_address}} = $resol_arp{hostname_fq};
     
    12511287
    12521288         my $switch = $where{$ip}->{$switch_detected};
     1289#print "DEBUG1 :  $db_switch_ip_hostname{$ip} / $switch->{hostname} : $switch->{port}\n" if  $switch->{hostname} =~ m/sw3-batA0-3s/;
    12531290
    12541291         next if $switch->{port}     eq '0';
     
    12581295         $db_switch_link_with{ $db_switch_ip_hostname{$ip} } ||= {};
    12591296         $db_switch_link_with{ $db_switch_ip_hostname{$ip} }->{ $switch->{hostname} } = $switch->{port};
     1297#print "DEBUG :  $db_switch_ip_hostname{$ip} / $switch->{hostname} : $switch->{port}\n" if $switch->{hostname} !~ m/sw3-batA0-3s/;
    12601298         }
    12611299
Note: See TracChangeset for help on using the changeset viewer.