Index: trunk/klask
===================================================================
--- trunk/klask	(revision 43)
+++ trunk/klask	(revision 44)
@@ -9,5 +9,6 @@
 
 use Net::SNMP;
-use YAML;
+#use YAML;
+use YAML::Syck;
 use Net::Netmask;
 use Net::CIDR::Lite;
@@ -26,5 +27,5 @@
 test_running_environnement();
 
-my $KLASK_CFG = YAML::LoadFile("$KLASK_CFG_FILE");
+my $KLASK_CFG = YAML::Syck::LoadFile("$KLASK_CFG_FILE");
 
 my %DEFAULT = %{$KLASK_CFG->{default}};
@@ -84,5 +85,4 @@
    J9022A => { model => 'HP2810-48G', match => 'ProCurve J9022A Switch 2810-48G' },
    J4903A => { model => 'HP2824',     match => 'J4903A.+?Switch 2824,'           },
-   J8692A => { model => 'HP3500-24G', match => 'J8692A'                          },
    J4110A => { model => 'HP8000M',    match => 'HP J4110A ProCurve Switch 8000M' },
    BS350T => { model => 'BS350T',     match => 'BayStack 350T HW'                },
@@ -145,4 +145,7 @@
 
 #   my $cmdarping  = `arping -c 1 -w 1 -rR $param 2>/dev/null`;
+   if (not $param_ip_or_host =~ m/^\d+\.\d+\.\d+\.\d+$/) {
+      $param_ip_or_host =~ s/\..*//;
+      }
 
    # controler que arpwatch tourne !
@@ -150,12 +153,14 @@
    # /var/lib/arpwatch/arp.dat
    # 0:13:d3:e1:92:d0        192.168.24.109  1163681980      theo8sv109
-   #my $cmd = "grep  -e '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/arp.dat | sort +2rn | head -1";
-#   my $cmd = "grep  -he '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/*.dat | sort +2rn | head -1";
-   my $cmd = "grep  -he '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/$interface.dat | sort -rn -k 2 | head -1";
+   # my $cmd = "grep  -e '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/arp.dat | sort +2rn | head -1";
+   # my $cmd = "grep  -he '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/*.dat | sort +2rn | head -1";
+   my $cmd = "grep  -he '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1";
    my $cmd_arpwatch = `$cmd`;
    chomp $cmd_arpwatch;
    my ($arp, $ip, $timestamp, $host) = split /\s+/, $cmd_arpwatch;
+
 #print "OOO $cmd\n";
 #print "TTT arp $arp -> $ip pour host $host\n";
+
    $ret{ipv4_address} = $ip        if $ip;
    $ret{mac_address}  = $arp       if $arp;
@@ -171,4 +176,5 @@
   # resultat de la commande arp
    # tech7meylan.hmg.inpg.fr (194.254.66.240) at 00:14:22:45:28:A9 [ether] on eth0
+   # sw2-batF0-legi.hmg.priv (192.168.22.112) at 00:30:c1:76:9c:01 [ether] on eth0.37
    my $cmd_arp  = `arp -a $param_ip_or_host 2>/dev/null`;
    chomp $cmd_arp;
@@ -177,4 +183,5 @@
    $ret{ipv4_address} = $2 if(defined($2));
    $ret{mac_address}  = $3 if(defined($3));
+#print "RET1 $ret{ipv4_address} -> $ret{mac_address} : $ret{hostname_fq}\n";
 
 #   if ($ret{ipv4_address} eq '0.0.0.0' and $ret{mac_address} eq 'unknow'and $ret{hostname_fq} eq 'unknow') {
@@ -188,6 +195,7 @@
       # resultat de la commande host si parametre est hostname
       # tech7meylan.hmg.inpg.fr has address 194.254.66.240
-      $cmd_host =~ m/\shas\saddress\s([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$/;
-      $ret{ipv4_address} = $1 if defined $1;
+      $cmd_host =~ m/(\S*)\shas\saddress\s([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$/;
+      $ret{hostname_fq}  = $1 if defined $1;
+      $ret{ipv4_address} = $2 if defined $2;
 
       $cmd_host =~ m/\b([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.in-addr\.arpa\s/;
@@ -196,4 +204,5 @@
 #      }
 
+#print "RET2 $ret{ipv4_address} -> $ret{mac_address} : $ret{hostname_fq}\n";
    unless ($ret{mac_address} eq 'unknow') {
       my @paquets = ();
@@ -205,4 +214,5 @@
       }
 
+#print "RET3 $ret{ipv4_address} -> $ret{mac_address} : $ret{hostname_fq}\n";
    return %ret;
    }
@@ -533,5 +543,5 @@
 
    fastping(@computer);
-   my $computerdb = YAML::LoadFile("$KLASK_DB_FILE");
+   my $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE");
    
    LOOP_ON_COMPUTER:
@@ -564,5 +574,5 @@
 
    my $computerdb = {};
-      $computerdb = YAML::LoadFile("$KLASK_DB_FILE") if -e "$KLASK_DB_FILE";
+      $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE") if -e "$KLASK_DB_FILE";
    my $timestamp = time;
 
@@ -579,5 +589,5 @@
 
    { # Remplis le champs portignore des ports d'inter-connection pour chaque switch
-   my $switch_connection = YAML::LoadFile("$KLASK_SW_FILE");
+   my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE");
    my %db_switch_output_port       = %{$switch_connection->{output_port}};
    my %db_switch_connected_on_port = %{$switch_connection->{connected_on_port}};
@@ -724,5 +734,5 @@
       $dirdb =~ s#/[^/]*$##;
    mkdir "$dirdb", 0755 unless -d "$dirdb";
-   YAML::DumpFile("$KLASK_DB_FILE", $computerdb);
+   YAML::Syck::DumpFile("$KLASK_DB_FILE", $computerdb);
 
    for my $one_computer (keys %computer_not_detected) {
@@ -738,5 +748,5 @@
    test_maindb_environnement();
 
-   my $computerdb = YAML::LoadFile("$KLASK_DB_FILE");
+   my $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE");
 
    LOOP_ON_COMPUTER:
@@ -751,5 +761,5 @@
       $dirdb =~ s#/[^/]*$##;
    mkdir "$dirdb", 0755 unless -d "$dirdb";
-   YAML::DumpFile("$KLASK_DB_FILE", $computerdb);
+   YAML::Syck::DumpFile("$KLASK_DB_FILE", $computerdb);
    }
 
@@ -757,5 +767,5 @@
    test_maindb_environnement();
 
-   my $computerdb = YAML::LoadFile("$KLASK_DB_FILE");
+   my $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE");
 
    printf "%-24s %-4s            %-30s %-15s %-18s %-s\n", qw(Switch Port Hostname IPv4-Address MAC-Address Date);
@@ -789,5 +799,5 @@
 
 sub cmd_iplocation {
-   my $computerdb = YAML::LoadFile("$KLASK_DB_FILE");
+   my $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE");
 
    LOOP_ON_IP_ADDRESS:
@@ -889,7 +899,8 @@
 #   for my $one_computer ('194.254.66.254') {
    for my $one_router ( get_list_main_router(get_list_network()) ) {
+print "TT$one_router\n";      
       my %resol_arp = resolve_ip_arp_host($one_router,'*','low');            # resolution arp
       next DETECT_ALL_ROUTER if $resol_arp{mac_address} eq 'unknow';
-      
+print "$one_router\n";      
       $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address}); # retrouve les emplacements des routeurs
       }
@@ -1054,5 +1065,5 @@
       };
       
-   YAML::DumpFile("$KLASK_SW_FILE", $switch_connection);
+   YAML::Syck::DumpFile("$KLASK_SW_FILE", $switch_connection);
    }
 
@@ -1080,5 +1091,5 @@
 sub cmd_exportsw_txt {
 
-   my $switch_connection = YAML::LoadFile("$KLASK_SW_FILE");
+   my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE");
 
    my %db_switch_output_port       = %{$switch_connection->{output_port}};
@@ -1115,5 +1126,5 @@
 sub cmd_exportsw_dot {
 
-   my $switch_connection = YAML::LoadFile("$KLASK_SW_FILE");
+   my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE");
    
    my %db_switch_output_port       = %{$switch_connection->{output_port}};
