Changeset 144
- Timestamp:
- Jan 9, 2016, 10:22:29 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r143 r144 141 141 sysLocation => '1.3.6.1.2.1.1.6.0', 142 142 searchPort1 => '1.3.6.1.2.1.17.4.3.1.2', # BRIDGE-MIB (802.1D). 143 searchPort2 => '1.3.6.1.2.1.17.7.1.2.2.1.2 .0', # Q-BRIDGE-MIB (802.1Q) replace last 0 with real vlan number if needed143 searchPort2 => '1.3.6.1.2.1.17.7.1.2.2.1.2', # Q-BRIDGE-MIB (802.1Q) add 0 if unknown vlan id 144 144 vlanPortDefault => '1.3.6.1.2.1.17.7.1.4.5.1.1', # dot1qPvid 145 145 vlanStatus => '1.3.6.1.2.1.17.7.1.4.3.1.5', # integer 4 Create, 6 Destroy … … 229 229 230 230 # my $cmd = q{grep -he '\b} . $param_ip_or_host . q{\b' } . "/var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1"; 231 my $cmd = q{grep -he '\b} . $ret{ipv4_address} . q{\b' } . "/var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1"; 231 #my $cmd = q{grep -he '\b} . $ret{ipv4_address} . q{\b' } . "/var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1"; 232 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'; 233 #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 234 232 235 my $cmd_arpwatch = shell_command $cmd; 233 my ($arp, $ip, $timestamp, $host) = split m/ \s+ /xms, $cmd_arpwatch; 234 236 #my ($arp, $ip, $timestamp, $host) = split m/ \s+ /xms, $cmd_arpwatch; 237 my ($interface2, $arp, $ip, $timestamp, $host) = split m/ \s+ /xms, $cmd_arpwatch; 238 239 $ret{interface} = $interface2 || $interface; 235 240 $ret{mac_address} = $arp if $arp; 236 241 $ret{timestamp} = $timestamp if $timestamp; … … 246 251 # tech7meylan.hmg.inpg.fr (194.254.66.240) at 00:14:22:45:28:A9 [ether] on eth0 247 252 # sw2-batF0-legi.hmg.priv (192.168.22.112) at 00:30:c1:76:9c:01 [ether] on eth0.37 248 my $cmd_arp = shell_command "arp -a $param_ip_or_host ";253 my $cmd_arp = shell_command "arp -a $param_ip_or_host -i $ret{interface}"; 249 254 if ( $cmd_arp =~ m{ (\S*) \s \( ( $RE_IPv4_ADDRESS ) \) \s at \s ( $RE_MAC_ADDRESS ) }xms ) { 250 255 ( $ret{hostname_fq}, $ret{ipv4_address}, $ret{mac_address} ) = ($1, $2, $3); … … 375 380 my $mac_address = shift; 376 381 my $switch_proposal = shift || q{}; 382 my $vlan_id = shift || 0; 377 383 378 384 my %ret; … … 392 398 393 399 my $research1 = $OID_NUMBER{searchPort1} . mac_address_hex_to_dec($mac_address); 394 my $research2 = $OID_NUMBER{searchPort2} . mac_address_hex_to_dec($mac_address);400 my $research2 = $OID_NUMBER{searchPort2} .'.'. $vlan_id . mac_address_hex_to_dec($mac_address); 395 401 396 402 LOOP_ON_SWITCH: … … 447 453 sub find_all_switch_port { 448 454 my $mac_address = shift; 455 my $vlan_id = shift || 0; 449 456 450 457 my $ret = {}; … … 460 467 461 468 my $research1 = $OID_NUMBER{searchPort1} . mac_address_hex_to_dec($mac_address); 462 my $research2 = $OID_NUMBER{searchPort2} . mac_address_hex_to_dec($mac_address);469 my $research2 = $OID_NUMBER{searchPort2} .'.'. $vlan_id . mac_address_hex_to_dec($mac_address); 463 470 LOOP_ON_ALL_SWITCH: 464 471 for my $sw (@SWITCH) { … … 503 510 } 504 511 512 sub get_current_vlan_id { 513 my $vlan_name = shift; 514 515 return $KLASK_CFG->{network}{$vlan_name}{'vlan-id'}; 516 } 517 518 sub get_current_vlan_name_for_interface { 519 my $interface = shift; 520 521 for my $vlan_name (keys %{$KLASK_CFG->{network}}) { 522 next if $KLASK_CFG->{network}{$vlan_name}{interface} ne $interface; 523 return $vlan_name; 524 } 525 } 526 505 527 ### 506 528 # liste l'ensemble des adresses ip d'un réseau … … 698 720 for my $clientname (@computer) { 699 721 my %resol_arp = resolve_ip_arp_host($clientname); #resolution arp 700 my %where = find_switch_port($resol_arp{mac_address}); #retrouve l'emplacement 722 my $vlan_name = get_current_vlan_name_for_interface($resol_arp{interface}); 723 my $vlan_id = get_current_vlan_id($vlan_name); 724 my %where = find_switch_port($resol_arp{mac_address}, '', $vlan_id); #retrouve l'emplacement 701 725 702 726 next LOOP_ON_COMPUTER if $where{switch_description} eq 'unknow' or $resol_arp{hostname_fq} eq 'unknow' or $resol_arp{mac_address} eq 'unknow'; … … 1471 1495 1472 1496 my $research1 = $OID_NUMBER{searchPort1} . mac_address_hex_to_dec($mac_address); 1473 my $research2 = $OID_NUMBER{searchPort2} . mac_address_hex_to_dec($mac_address);1497 my $research2 = $OID_NUMBER{searchPort2} .'.'. 0 . mac_address_hex_to_dec($mac_address); 1474 1498 print "Klask search OID $research1 on switch $sw_name\n"; 1475 1499 print "Klask search OID $research2 on switch $sw_name\n"; … … 1839 1863 1840 1864 my $verbose; 1865 my $vlan_id = 0; 1841 1866 1842 1867 GetOptions( 1843 1868 'verbose|v' => \$verbose, 1869 'vlan|l=i' => \$vlan_id, 1844 1870 ); 1845 1871 … … 1871 1897 1872 1898 my $research1 = $OID_NUMBER{searchPort1} . mac_address_hex_to_dec($mac_address); 1873 my $research2 = $OID_NUMBER{searchPort2} . mac_address_hex_to_dec($mac_address);1899 my $research2 = $OID_NUMBER{searchPort2} .'.'. $vlan_id . mac_address_hex_to_dec($mac_address); 1874 1900 print "Klask search OID $research1 on switch $sw_name\n" if $verbose; 1875 1901 print "Klask search OID $research2 on switch $sw_name\n" if $verbose; … … 1925 1951 print "VERBOSE_1: Router detected $resol_arp{ipv4_address} - $resol_arp{mac_address}\n" if $verbose; 1926 1952 1927 $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address}); # retrouve les emplacements des routeurs 1953 my $vlan_name = get_current_vlan_name_for_interface($resol_arp{interface}); 1954 my $vlan_id = get_current_vlan_id($vlan_name); 1955 $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address},$vlan_id); # retrouve les emplacements des routeurs 1928 1956 } 1929 1957 … … 1962 1990 push @list_switch_ipv4, $resol_arp{ipv4_address}; 1963 1991 1964 $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address}); # find port on all switch 1992 my $vlan_name = get_current_vlan_name_for_interface($resol_arp{interface}); 1993 my $vlan_id = get_current_vlan_id($vlan_name); 1994 $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address},$vlan_id); # find port on all switch 1965 1995 1966 1996 if ($verbose) {
Note: See TracChangeset
for help on using the changeset viewer.