- Timestamp:
- Oct 4, 2018, 10:36:06 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r402 r404 298 298 $ret{'hostname_fq'} = $hostname_fq if defined $hostname_fq; 299 299 300 # my $cmd = q{grep -he '\b} . $param_ip_or_host . q{\b' } . "/var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1"; 301 #my $cmd = q{grep -he '\b} . $ret{'ipv4_address'} . q{\b' } . "/var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1"; 302 my $cmd = q{grep -He '\b} . $ret{'ipv4_address'} . q{\b' } . "/var/lib/arpwatch/$interface.dat" . '| sed -e \'s|^/var/lib/arpwatch/\(.*\)\.dat:|\1 |;\' | sort -rn -k 4,4 | head -1'; 303 #grep -He 194.254.66.252 /var/lib/arpwatch/*.dat | sed -e 's|^/var/lib/arpwatch/\(.*\)\.dat:|\1\t|;' | sort -rn -k 4,4 | head -1 304 300 my $cmd = q{grep -He '\b} 301 . $ret{'ipv4_address'} . q{\b' } 302 . "/var/lib/arpwatch/$interface.dat" 303 . '| sed -e \'s|^/var/lib/arpwatch/\(.*\)\.dat:|\1 |;\' | sort -rn -k 4,4 | head -1'; 305 304 my $cmd_arpwatch = shell_command $cmd; 306 #my ($arp, $ip, $timestamp, $host) = split m/ \s+ /xms, $cmd_arpwatch;307 305 my ($interface2, $arp, $ip, $timestamp, $host) = split m/ \s+ /xms, $cmd_arpwatch; 308 306 … … 661 659 } 662 660 663 $ret->{$sw->{'hostname'}} = {};661 $ret->{$sw->{'hostname'}} = {}; 664 662 $ret->{$sw->{'hostname'}}{'hostname'} = $sw->{'hostname'}; 665 663 $ret->{$sw->{'hostname'}}{'description'} = $sw->{'description'}; … … 1252 1250 LOOP_ON_COMPUTER: 1253 1251 for my $clientname (@computer) { 1254 my %resol_arp = resolve_ip_arp_host($clientname); # resolution arp1252 my %resol_arp = resolve_ip_arp_host($clientname); # resolution arp 1255 1253 my $vlan_name = get_current_vlan_name_for_interface($resol_arp{'interface'}); 1256 1254 my $vlan_id = get_current_vlan_id($vlan_name); 1257 1255 my %where = find_switch_port($resol_arp{'mac_address'}, '', $vlan_id); # retrouve l'emplacement 1258 1256 1259 next LOOP_ON_COMPUTER if $where{'switch_description'} eq 'unknow' or $resol_arp{'hostname_fq'} eq 'unknow' or $resol_arp{'mac_address'} eq 'unknow'; 1257 next LOOP_ON_COMPUTER 1258 if $where{'switch_description'} eq 'unknow' 1259 or $resol_arp{'hostname_fq'} eq 'unknow' 1260 or $resol_arp{'mac_address'} eq 'unknow'; 1260 1261 1261 1262 printf '%-22s %2s %-30s %-15s %18s', … … 1386 1387 1387 1388 { 1388 my $switch_checksum = get_switchdb_checksum(%SWITCH_DB);1389 # Remplis le champs portignore des ports d'inter-connection pour chaque switch1390 my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE");1391 if ($switch_checksum ne $switch_connection->{'checksum'}) { # Verify checksum1392 if ($no_rebuildsw) {1393 print "WARNING: switch database is outdate, please rebuild if with updatesw command\n";1394 }1395 else {1396 print "WARNING: switch database is going to be rebuilt\n";1397 update_switchdb(verbose => $verbose)1398 }1399 }1400 1401 my %db_switch_output_port = %{$switch_connection->{'output_port'}};1402 my %db_switch_connected_on_port = %{$switch_connection->{'connected_on_port'}};1403 my %db_switch_chained_port = ();1404 for my $swport (keys %db_switch_connected_on_port) {1405 my ($sw_connect, $port_connect) = split m/ $SEP_SWITCH_PORT /xms, $swport, 2;1406 $db_switch_chained_port{$sw_connect} .= "$port_connect:";1407 }1408 for my $sw (@SWITCH_LIST) {1409 push @{$sw->{'portignore'}}, $db_switch_output_port{$sw->{'hostname'}}if exists $db_switch_output_port{$sw->{'hostname'}};1410 if ( exists $db_switch_chained_port{$sw->{'hostname'}}) {1411 chop $db_switch_chained_port{$sw->{'hostname'}};1412 push @{$sw->{'portignore'}}, split m/ : /xms, $db_switch_chained_port{$sw->{'hostname'}};1413 }1414 #print "$sw->{'hostname'} ++ @{$sw->{'portignore'}}\n";1415 }1416 }1389 my $switch_checksum = get_switchdb_checksum(%SWITCH_DB); 1390 # Remplis le champs portignore des ports d'inter-connection pour chaque switch 1391 my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE"); 1392 if ($switch_checksum ne $switch_connection->{'checksum'}) { # Verify checksum 1393 if ($no_rebuildsw) { 1394 print "WARNING: switch database is outdate, please rebuild if with updatesw command\n"; 1395 } 1396 else { 1397 print "WARNING: switch database is going to be rebuilt\n"; 1398 update_switchdb(verbose => $verbose) 1399 } 1400 } 1401 1402 my %db_switch_output_port = %{$switch_connection->{'output_port'}}; 1403 my %db_switch_connected_on_port = %{$switch_connection->{'connected_on_port'}}; 1404 my %db_switch_chained_port = (); 1405 for my $swport (keys %db_switch_connected_on_port) { 1406 my ($sw_connect, $port_connect) = split m/ $SEP_SWITCH_PORT /xms, $swport, 2; 1407 $db_switch_chained_port{$sw_connect} .= "$port_connect:"; 1408 } 1409 for my $sw (@SWITCH_LIST) { 1410 push @{$sw->{'portignore'}}, $db_switch_output_port{$sw->{'hostname'}} if exists $db_switch_output_port{$sw->{'hostname'}}; 1411 if (exists $db_switch_chained_port{$sw->{'hostname'}}) { 1412 chop $db_switch_chained_port{$sw->{'hostname'}}; 1413 push @{$sw->{'portignore'}}, split m/ : /xms, $db_switch_chained_port{$sw->{'hostname'}}; 1414 } 1415 #print "$sw->{'hostname'} ++ @{$sw->{'portignore'}}\n"; 1416 } 1417 } 1417 1418 1418 1419 my %router_mac_ip = (); … … 1471 1472 1472 1473 # do not have a mac address 1473 if ($resol_arp{'mac_address'} eq 'unknow' or (exists $resol_arp{'timestamps'} and $resol_arp{'timestamps'} < ($timestamp - 3 * 3600))) { 1474 if ($resol_arp{'mac_address'} eq 'unknow' 1475 or (exists $resol_arp{'timestamps'} and $resol_arp{'timestamps'} < ($timestamp - 3 * 3600)) 1476 ) { 1474 1477 $computer_not_detected{$one_computer} = $current_net; 1475 1478 next LOOP_ON_COMPUTER; … … 1528 1531 1529 1532 # mise à jour de la date de détection si détection plus récente par arpwatch 1530 $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'} = $resol_arp{'timestamp'} if exists $resol_arp{'timestamp'} and $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'} < $resol_arp{'timestamp'}; 1533 $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'} = $resol_arp{'timestamp'} 1534 if exists $resol_arp{'timestamp'} and $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'} < $resol_arp{'timestamp'}; 1531 1535 1532 1536 # relance un arping sur la machine si celle-ci n'a pas été détectée depuis plus d'une semaine 1533 # push @computer_not_detected, $resol_arp{'ipv4_address'} if $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'} < $timestamp_last_week;1534 $computer_not_detected{$resol_arp{'ipv4_address'}} = $current_netif $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'} < $timestamp_last_week;1537 $computer_not_detected{$resol_arp{'ipv4_address'}} = $current_net 1538 if $computerdb->{$resol_arp{'ipv4_address'}}{'timestamp'} < $timestamp_last_week; 1535 1539 1536 1540 } … … 1545 1549 my $current_net = $computer_not_detected{$one_computer}; 1546 1550 my $current_interface = get_current_interface($current_net); 1547 system "arping -c 1 -w 1 -rR -i $current_interface $one_computer > /dev/null 2>&1" if get_current_scan_mode($current_net) eq 'active'; 1551 system "arping -c 1 -w 1 -rR -i $current_interface $one_computer > /dev/null 2>&1" 1552 if get_current_scan_mode($current_net) eq 'active'; 1548 1553 } 1549 1554 return; … … 1807 1812 1808 1813 # to be improve in the future 1809 next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{'hostname_fq'} eq ($computerdb->{$ip}{'switch_hostname'} || $computerdb->{$ip}{'switch_description'}); # switch on himself ! 1814 next LOOP_ON_IP_ADDRESS 1815 if $computerdb->{$ip}{'hostname_fq'} eq ($computerdb->{$ip}{'switch_hostname'} || $computerdb->{$ip}{'switch_description'}); # switch on himself ! 1810 1816 1811 1817 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime $computerdb->{$ip}{'timestamp'}; … … 1910 1916 1911 1917 my $vlan = ''; 1912 $vlan = $computerdb->{$ip}{'network'}.' ('.get_current_vlan_id($computerdb->{$ip}{'network'}).')' if $computerdb->{$ip}{'network'}; 1918 $vlan = $computerdb->{$ip}{'network'} . ' (' . get_current_vlan_id($computerdb->{$ip}{'network'}) . ')' 1919 if $computerdb->{$ip}{'network'}; 1913 1920 1914 1921 my $parent_port_hr = format_aggregator4html($computerdb->{$ip}{'switch_port_hr'}); … … 2788 2795 LOOP_ON_DATABASE: 2789 2796 for my $ip_db (keys %{$computerdb}) { 2790 next LOOP_ON_DATABASE if $computerdb->{$ip_db}{'mac_address'} ne $mac_address;2797 next LOOP_ON_DATABASE if $computerdb->{$ip_db}{'mac_address'} ne $mac_address; 2791 2798 next LOOP_ON_IP_ADDRESS if $computerdb->{$ip_db}{'timestamp'} > $timestamp_barrier; 2792 2799 } … … 2803 2810 my $packed_ip = scalar gethostbyname($ip); 2804 2811 my $hostname_fq = 'unknown'; 2805 $hostname_fq = scalar gethostbyaddr($packed_ip, AF_INET) || 'unknown' if defined $packed_ip and get_current_scan_mode($vlan) eq 'active'; 2812 $hostname_fq = scalar gethostbyaddr($packed_ip, AF_INET) || 'unknown' 2813 if defined $packed_ip and get_current_scan_mode($vlan) eq 'active'; 2806 2814 2807 2815 next LOOP_ON_IP_ADDRESS if $hostname_fq =~ m/$RE_FLOAT_HOSTNAME/; … … 3149 3157 3150 3158 my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE"); 3151 my $interway = 0;3159 my $interway = 0; 3152 3160 3153 3161 if ($args{'way'} =~ m/all|desc/) {
Note: See TracChangeset
for help on using the changeset viewer.