Changeset 83
- Timestamp:
- Mar 30, 2011, 11:22:07 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r82 r83 28 28 my $KLASK_DB_FILE = "$KLASK_VAR/klaskdb"; 29 29 my $KLASK_SW_FILE = "$KLASK_VAR/switchdb"; 30 31 #my $DEBUG = 0; 32 #GetOptionsFromArray(\@ARGV, 33 # 'debug|d=i' => \$DEBUG, 34 # ); 30 35 31 36 test_running_environnement(); … … 428 433 429 434 for my $sw (@SWITCH) { 430 $SWITCH_PORT_COUNT{$sw->{hostname}} = {} if not exists $SWITCH_PORT_COUNT{$sw->{hostname}}; 435 next if exists $SWITCH_PORT_COUNT{$sw->{hostname}}; 436 437 $SWITCH_PORT_COUNT{$sw->{hostname}} = {}; 438 # print "DEBUG: SWITCH_PORT_COUNT defined for $sw->{hostname}\n" if $DEBUG xor 2; 431 439 } 432 440 … … 1433 1441 my %where = (); 1434 1442 my %db_switch_output_port = (); 1435 my %db_switch_ip_hostname = ();1443 my %db_switch_ip_hostnamefq = (); 1436 1444 1437 1445 DETECT_ALL_ROUTER: … … 1439 1447 for my $one_router ( get_list_main_router(get_list_network()) ) { 1440 1448 my %resol_arp = resolve_ip_arp_host($one_router, q{*}, q{low}); # resolution arp 1449 1441 1450 next DETECT_ALL_ROUTER if $resol_arp{mac_address} eq 'unknow'; 1451 print "VERBOSE_1: Router detected $resol_arp{ipv4_address} - $resol_arp{mac_address}\n" if $verbose; 1452 1442 1453 $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address}); # retrouve les emplacements des routeurs 1443 print "VERBOSE_1: Router detected $resol_arp{ipv4_address} - $resol_arp{mac_address}\n" if $verbose;1444 1454 } 1445 1455 1446 1456 ALL_ROUTER_IP_ADDRESS: 1447 for my $ip (Net::Netmask::sort_by_ip_address(keys %where)) { # '194.254.66.254')) {1448 1449 next ALL_ROUTER_IP_ADDRESS if not exists $where{$ip }; # /a priori/ idiot car ne sers à rien...1457 for my $ip_router (Net::Netmask::sort_by_ip_address(keys %where)) { # '194.254.66.254')) { 1458 1459 next ALL_ROUTER_IP_ADDRESS if not exists $where{$ip_router}; # /a priori/ idiot car ne sers à rien... 1450 1460 1451 1461 ALL_SWITCH_CONNECTED: 1452 for my $switch_detected ( keys %{$where{$ip }} ) {1453 1454 my $switch = $where{$ip }->{$switch_detected};1462 for my $switch_detected ( keys %{$where{$ip_router}} ) { 1463 1464 my $switch = $where{$ip_router}->{$switch_detected}; 1455 1465 1456 1466 next ALL_SWITCH_CONNECTED if $switch->{port} eq '0'; … … 1463 1473 my %db_switch_link_with = (); 1464 1474 1465 my @list_ switch_ip= ();1475 my @list_all_switch = (); 1466 1476 my @list_switch_ipv4 = (); 1467 1477 for my $sw (@SWITCH){ 1468 push @list_ switch_ip, $sw->{hostname};1478 push @list_all_switch, $sw->{hostname}; 1469 1479 } 1470 1480 … … 1472 1482 1473 1483 ALL_SWITCH: 1474 for my $one_computer (@list_ switch_ip) {1484 for my $one_computer (@list_all_switch) { 1475 1485 my %resol_arp = resolve_ip_arp_host($one_computer, q{*}, q{low}); # arp resolution 1476 1486 next ALL_SWITCH if $resol_arp{mac_address} eq 'unknow'; … … 1481 1491 1482 1492 if ($verbose) { 1483 # my @l = (); 1484 # for my $c ( keys %{$where{$resol_arp{ipv4_address}}} ) { 1485 # push @l, "$c -+ "; #$where{$resol_arp{ipv4_address}}->{$c}{hostname}; 1486 # } 1487 print "VERBOSE_3 $one_computer $resol_arp{ipv4_address} $resol_arp{mac_address}\n"; 1488 print "VERBOSE_3 $one_computer --- ", 1493 print "VERBOSE_3: $one_computer $resol_arp{ipv4_address} $resol_arp{mac_address}\n"; 1494 print "VERBOSE_3: $one_computer --- ", 1489 1495 join(' + ', keys %{$where{$resol_arp{ipv4_address}}}), 1490 1496 "\n"; 1491 1497 } 1492 1498 1493 $db_switch_ip_hostname{$resol_arp{ipv4_address}} = $resol_arp{hostname_fq}; 1499 $db_switch_ip_hostnamefq{$resol_arp{ipv4_address}} = $resol_arp{hostname_fq}; 1500 print "VERBOSE_4: db_switch_ip_hostnamefq $resol_arp{ipv4_address} -> $resol_arp{hostname_fq}\n" if $verbose; 1494 1501 1495 1502 $SWITCH_DB{$one_computer}->{ipv4_address} = $resol_arp{ipv4_address}; … … 1501 1508 for my $ip (Net::Netmask::sort_by_ip_address(@list_switch_ipv4)) { 1502 1509 1510 print "VERBOSE_5: loop on $db_switch_ip_hostnamefq{$ip}\n" if $verbose; 1511 1503 1512 next ALL_SWITCH_IP_ADDRESS if not exists $where{$ip}; 1513 next ALL_SWITCH_IP_ADDRESS if not exists $SWITCH_PORT_COUNT{ $db_switch_ip_hostnamefq{$ip} }; 1504 1514 1505 1515 DETECTED_SWITCH: 1506 1516 for my $switch_detected ( keys %{$where{$ip}} ) { 1507 1517 1508 next DETECTED_SWITCH if not exists $SWITCH_PORT_COUNT{ $db_switch_ip_hostname{$ip} };1509 1510 1518 my $switch = $where{$ip}->{$switch_detected}; 1511 print "VERBOSE_ 4: $db_switch_ip_hostname{$ip} -> $switch->{hostname} : $switch->{port}\n" if $verbose;1519 print "VERBOSE_6: $db_switch_ip_hostnamefq{$ip} -> $switch->{hostname} : $switch->{port}\n" if $verbose; 1512 1520 1513 1521 next if $switch->{port} eq '0'; 1514 1522 next if $switch->{port} eq $db_switch_output_port{$switch->{hostname}}; 1515 next if $switch->{hostname} eq $db_switch_ip_hostname {$ip}; # $computerdb->{$ip}{hostname};1516 1517 $db_switch_link_with{ $db_switch_ip_hostname {$ip} } ||= {};1518 $db_switch_link_with{ $db_switch_ip_hostname {$ip} }->{ $switch->{hostname} } = $switch->{port};1519 print "VERBOSE_ 5: $db_switch_ip_hostname{$ip} -> $switch->{hostname} : $switch->{port}\n" if $verbose;1523 next if $switch->{hostname} eq $db_switch_ip_hostnamefq{$ip}; # $computerdb->{$ip}{hostname}; 1524 1525 $db_switch_link_with{ $db_switch_ip_hostnamefq{$ip} } ||= {}; 1526 $db_switch_link_with{ $db_switch_ip_hostnamefq{$ip} }->{ $switch->{hostname} } = $switch->{port}; 1527 print "VERBOSE_7: +++++\n" if $verbose; 1520 1528 } 1521 1529
Note: See TracChangeset
for help on using the changeset viewer.