Changeset 136
- Timestamp:
- Mar 31, 2014, 5:48:40 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r135 r136 338 338 } 339 339 340 ### 340 #-------------------------------------------------------------------------------- 341 342 sub normalize_mac_address { 343 my $mac_address = shift; 344 345 return join q{:}, map { substr( uc("00$_"), -2) } split m/ [:-] /xms, $mac_address; 346 } 347 348 #-------------------------------------------------------------------------------- 341 349 # convertit l'@ mac en decimal 342 350 sub mac_address_hex_to_dec { … … 695 703 696 704 sub cmd_searchdb { 705 my @ARGV = @_; 706 707 my $kind; 708 709 my $ret = GetOptions( 710 'kind' => \$kind, 711 ); 712 713 if 714 715 my %possible_search = ( 716 host => \&cmd_searchdb_host, 717 mac => \&cmd_searchdb_mac, 718 ); 719 720 $search = 'host' if not defined $possible_search{$kind}; 721 722 $possible_search{$kind}->(@ARGV); 723 return; 724 } 725 726 727 sub cmd_searchdb_host { 697 728 my @computer = @_; 698 729 … … 719 750 $computerdb->{$ip}{mac_address}, 720 751 $date; 752 } 753 return; 754 } 755 756 sub cmd_searchdb_mac { 757 my @mac = map { normalize_mac_address($_) } @_; 758 759 my $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE"); 760 761 LOOP_ON_MAC: 762 for my $mac (@mac) { 763 LOOP_ON_COMPUTER: 764 for my $ip (keys %{$computerdb}) { 765 next LOOP_ON_COMPUTER if $mac ne $computerdb->{$ip}{mac_address}; 766 767 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $computerdb->{$ip}{timestamp}; 768 $year += 1900; 769 $mon++; 770 my $date = sprintf '%04i-%02i-%02i %02i:%02i', $year, $mon, $mday, $hour, $min; 771 772 printf "%-22s %2s %-30s %-15s %-18s %s\n", 773 $computerdb->{$ip}{switch_hostname}, 774 $computerdb->{$ip}{switch_port}, 775 $computerdb->{$ip}{hostname_fq}, 776 $ip, 777 $computerdb->{$ip}{mac_address}, 778 $date; 779 next LOOP_ON_MAC; 780 } 781 721 782 } 722 783 return; … … 2098 2159 klask exportsw --format [txt|dot] 2099 2160 2100 klask searchdb computer2161 klask searchdb --kind [host|mac] computer [mac-address] 2101 2162 klask search computer 2102 2163 klask search-mac-on-switch switch mac_addr
Note: See TracChangeset
for help on using the changeset viewer.