Changeset 246
- Timestamp:
- Sep 8, 2017, 10:38:15 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r245 r246 7 7 use strict; 8 8 use warnings; 9 use version; our $VERSION = qv('0.6. 2');9 use version; our $VERSION = qv('0.6.3'); 10 10 11 11 use Readonly; … … 168 168 sysContact => '1.3.6.1.2.1.1.4.0', 169 169 sysLocation => '1.3.6.1.2.1.1.6.0', 170 searchPort1 => '1.3.6.1.2.1.17.4.3.1.2', # BRIDGE-MIB (802.1D).171 searchPort2 => '1.3.6.1.2.1.17.7.1.2.2.1.2', # Q-BRIDGE-MIB (802.1Q) add 0 if unknown vlan id172 vlanPortDefault => '1.3.6.1.2.1.17.7.1.4.5.1.1', # dot1qPvid173 vlanStatus => '1.3.6.1.2.1.17.7.1.4.3.1.5', # integer 4 Create, 6 Destroy174 vlanName => '1.3.6.1.2.1.17.7.1.4.3.1.1', # string175 HPicfReset => '1.3.6.1.4.1.11.2.14.11.1.4.1', # HP reboot switch176 ifIndex => '1.3.6.1.2.1.17.1.4.1.2', # dot1dBasePortIfIndex - Interface index redirection177 ifName => '1.3.6.1.2.1.31.1.1.1.1', # Interface name (give port number)178 portUpDown => '1.3.6.1.2.1.2.2.1.7', # 1.3.6.1.2.1.2.2.1.7.NoPort = 1 (up) = 2 (down)179 poeState => '1.3.6.1.2.1.105.1.1.1.3.1', # 1.3.6.1.2.1.105.1.1.1.3.1.NoPort = 1 (poe up) = 2 (poe down) - Cisco and Zyxel180 NApoeState => '1.3.6.1.4.1.266.20.3.1.1.21', # .NoPort = 2 (poe off) = 8 (poe atHighPower) - Nexans170 searchPort1 => '1.3.6.1.2.1.17.4.3.1.2', # BRIDGE-MIB (802.1D). 171 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 172 vlanPortDefault => '1.3.6.1.2.1.17.7.1.4.5.1.1', # dot1qPvid 173 vlanStatus => '1.3.6.1.2.1.17.7.1.4.3.1.5', # integer 4 Create, 6 Destroy 174 vlanName => '1.3.6.1.2.1.17.7.1.4.3.1.1', # string 175 HPicfReset => '1.3.6.1.4.1.11.2.14.11.1.4.1', # HP reboot switch 176 ifIndex => '1.3.6.1.2.1.17.1.4.1.2', # dot1dBasePortIfIndex - Interface index redirection 177 ifName => '1.3.6.1.2.1.31.1.1.1.1', # Interface name (give port number) 178 portUpDown => '1.3.6.1.2.1.2.2.1.7', # 1.3.6.1.2.1.2.2.1.7.NoPort = 1 (up) = 2 (down) 179 poeState => '1.3.6.1.2.1.105.1.1.1.3.1', # 1.3.6.1.2.1.105.1.1.1.3.1.NoPort = 1 (poe up) = 2 (poe down) - Cisco and Zyxel 180 NApoeState => '1.3.6.1.4.1.266.20.3.1.1.21', # .NoPort = 2 (poe off) = 8 (poe atHighPower) - Nexans 181 181 ifAggregator => '1.2.840.10006.300.43.1.2.1.1.12', # dot3adAggPortSelectedAggID - 0 not part of an Aggregator - Ciso Dell HP Comware - See https://stackoverflow.com/questions/14960157/how-to-map-portchannel-to-interfaces-via-snmp https://gist.github.com/bldewolf/6314435 182 182 ); … … 191 191 192 192 Readonly my $RE_FLOAT_HOSTNAME => $DEFAULT{'float-regex'} || qr{ ^float }xms; 193 194 Readonly my $SEP_AGGREGATOR_PORT => '|'; # : is already use to join switch and port 195 193 196 194 197 ################################################################ … … 341 344 } 342 345 346 #--------------------------------------------------------------- 343 347 # Find Surname of a switch 344 348 sub get_switch_model { … … 416 420 417 421 #--------------------------------------------------------------- 418 # convert it l'hexa (uniquement 2 chiffres) endecimal419 sub digit_hex _to_dec {422 # convert hexa (only 2 digits) to decimal 423 sub digit_hex2dec { 420 424 #00:0F:1F:43:E4:2B 421 425 my $car = '00' . uc shift; … … 448 452 449 453 #--------------------------------------------------------------- 450 # convert it l'@ mac endecimal451 sub mac_address_hex _to_dec {454 # convert MAC hex address to decimal 455 sub mac_address_hex2dec { 452 456 #00:0F:1F:43:E4:2B 453 457 my $mac_address = shift; … … 456 460 my $return = q{}; 457 461 for (@paquets) { 458 $return .= q{.} . digit_hex _to_dec($_);462 $return .= q{.} . digit_hex2dec($_); 459 463 } 460 464 return $return; … … 462 466 463 467 #--------------------------------------------------------------- 464 # va rechercher le port et le switch sur lequel est la machine468 # return the port and the switch where the computer is connected 465 469 sub find_switch_port { 466 470 my $mac_address = shift; … … 483 487 } 484 488 485 my $research1 = $OID_NUMBER{'searchPort1'} . mac_address_hex _to_dec($mac_address);486 my $research2 = $OID_NUMBER{'searchPort2'} .'.'. $vlan_id . mac_address_hex _to_dec($mac_address);489 my $research1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address); 490 my $research2 = $OID_NUMBER{'searchPort2'} .'.'. $vlan_id . mac_address_hex2dec($mac_address); 487 491 488 492 LOOP_ON_SWITCH: … … 520 524 for my $portignore (@{$sw->{portignore}}) { 521 525 next LOOP_ON_SWITCH if $swport_hr eq $portignore; 522 my ($swport_hr_limited) = split / |/, $swport_hr; # Beginning of the swith port (Aggregator)526 my ($swport_hr_limited) = split /$SEP_AGGREGATOR_PORT/, $swport_hr; # Beginning of the swith port (Aggregator) 523 527 next LOOP_ON_SWITCH if $swport_hr_limited eq $portignore; 524 528 } … … 535 539 536 540 #--------------------------------------------------------------- 537 # va rechercher les port et les switch sur lequel est la machine541 # search all the port on all the switches where the computer is detected 538 542 sub find_all_switch_port { 539 543 my $mac_address = shift; … … 544 548 return $ret if $mac_address eq 'unknow'; 545 549 546 my $research1 = $OID_NUMBER{'searchPort1'} . mac_address_hex _to_dec($mac_address);547 my $research2 = $OID_NUMBER{'searchPort2'} .'.'. $vlan_id . mac_address_hex _to_dec($mac_address);550 my $research1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address); 551 my $research2 = $OID_NUMBER{'searchPort2'} .'.'. $vlan_id . mac_address_hex2dec($mac_address); 548 552 LOOP_ON_ALL_SWITCH: 549 553 for my $sw (@SWITCH_LIST) { … … 578 582 $ret->{$sw->{hostname}}{port} = $swport_num; 579 583 $ret->{$sw->{hostname}}{port_hr} = $swport_hr; 580 581 # $SWITCH_PORT_COUNT{$sw->{hostname}}->{$swport}++;582 584 } 583 585 … … 702 704 # On H3C, port number and port index are not the same 703 705 # Double SNMP request to get the name 706 # First get the index, second get the name 704 707 705 708 my $research_index = $OID_NUMBER{ifIndex} .'.'. $swport_num; … … 746 749 747 750 my $current_port_name = snmp_get_switchport_index2hr($snmp_session, $current_port_index); 748 $swport_hr .= " |$current_port_name"; # Join with | (: is already use)751 $swport_hr .= "$SEP_AGGREGATOR_PORT$current_port_name"; 749 752 } 750 753 } … … 759 762 # Split for Aggregator port 760 763 # Keep only the Aggregator part 761 ($swport_hr) = split / |/, $swport_hr;764 ($swport_hr) = split /$SEP_AGGREGATOR_PORT/, $swport_hr; 762 765 763 766 my $swport_num = $swport_hr; 764 return $swport_num if $swport_num =~ m/^\d+$/; # direct return if already numeric (next loop is expensive) 767 # direct return if already numeric (next loop is expensive) / old or simple switch 768 return $swport_num if $swport_num =~ m/^\d+$/; 765 769 766 770 my $research_index = $OID_NUMBER{ifIndex}; # base OID … … 1851 1855 } 1852 1856 1853 my $research1 = $OID_NUMBER{'searchPort1'} . mac_address_hex _to_dec($mac_address);1854 my $research2 = $OID_NUMBER{'searchPort2'} .'.'. 0 . mac_address_hex _to_dec($mac_address);1857 my $research1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address); 1858 my $research2 = $OID_NUMBER{'searchPort2'} .'.'. 0 . mac_address_hex2dec($mac_address); 1855 1859 print "Klask search OID $research1 on switch $sw_name\n"; 1856 1860 print "Klask search OID $research2 on switch $sw_name\n"; … … 2363 2367 } 2364 2368 2365 my $research1 = $OID_NUMBER{'searchPort1'} . mac_address_hex _to_dec($mac_address);2366 my $research2 = $OID_NUMBER{'searchPort2'} .'.'. $vlan_id . mac_address_hex _to_dec($mac_address);2369 my $research1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address); 2370 my $research2 = $OID_NUMBER{'searchPort2'} .'.'. $vlan_id . mac_address_hex2dec($mac_address); 2367 2371 print "Klask search OID $research1 on switch $sw_name\n" if $verbose; 2368 2372 print "Klask search OID $research2 on switch $sw_name\n" if $verbose; … … 2824 2828 =head1 DESCRIPTION 2825 2829 2826 Klask is a small tool to find where is a host in a big network. 2830 Klask is a small tool to find where is connected a host in a big network 2831 and on which VLAN. 2827 2832 Klask mean search in brittany. 2828 2833 No hight level protocol like CDL, LLDP are use. … … 3114 3119 and also on input command line. 3115 3120 3121 In the case of use an aggregator port (Po, Tk, Br ...), 3122 the real ports used are also return. 3123 3116 3124 3117 3125 =head1 FILES
Note: See TracChangeset
for help on using the changeset viewer.