- Timestamp:
- Jul 24, 2009, 12:22:32 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r50 r51 8 8 use warnings; 9 9 10 use Readonly; 10 11 use Net::SNMP; 11 12 #use YAML; … … 60 61 ); 61 62 62 my %INTERNAL_PORT_MAP =(63 Readonly my %INTERNAL_PORT_MAP => ( 63 64 0 => 'A', 64 65 1 => 'B', … … 70 71 7 => 'H', 71 72 ); 72 my %INTERNAL_PORT_MAP_REV =reverse %INTERNAL_PORT_MAP;73 74 my %SWITCH_KIND =(73 Readonly my %INTERNAL_PORT_MAP_REV => reverse %INTERNAL_PORT_MAP; 74 75 Readonly my %SWITCH_KIND => ( 75 76 J3299A => { model => 'HP224M', match => 'HP J3299A ProCurve Switch 224M' }, 76 77 J4120A => { model => 'HP1600M', match => 'HP J4120A ProCurve Switch 1600M' }, … … 88 89 ); 89 90 90 my %OID_NUMBER =(91 sysDescription 92 sysName => '1.3.6.1.2.1.1.5.0',93 sysContact => '1.3.6.1.2.1.1.4.0',94 sysLocation => '1.3.6.1.2.1.1.6.0',91 Readonly my %OID_NUMBER => ( 92 sysDescription => '1.3.6.1.2.1.1.1.0', 93 sysName => '1.3.6.1.2.1.1.5.0', 94 sysContact => '1.3.6.1.2.1.1.4.0', 95 sysLocation => '1.3.6.1.2.1.1.6.0', 95 96 ); 97 98 Readonly my $RE_MAC_ADDRESS => qr{ [0-9,A-Z]{2} : [0-9,A-Z]{2} : [0-9,A-Z]{2} : [0-9,A-Z]{2} : [0-9,A-Z]{2} : [0-9,A-Z]{2} }xms; 99 Readonly my $RE_IPv4_ADDRESS => qr{ [0-9]{1,3} \. [0-9]{1,3} \. [0-9]{1,3} \. [0-9]{1,3} }xms; 100 96 101 97 102 ################ … … 177 182 # tech7meylan.hmg.inpg.fr (194.254.66.240) at 00:14:22:45:28:A9 [ether] on eth0 178 183 # sw2-batF0-legi.hmg.priv (192.168.22.112) at 00:30:c1:76:9c:01 [ether] on eth0.37 179 my $cmd_arp = `arp -a $param_ip_or_host 2> /dev/null`;184 my $cmd_arp = `arp -a $param_ip_or_host 2> /dev/null`; 180 185 chomp $cmd_arp; 181 $cmd_arp =~ /(\S*)\s\(([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\)\sat\s([0-9,A-Z]{2}:[0-9,A-Z]{2}:[0-9,A-Z]{2}:[0-9,A-Z]{2}:[0-9,A-Z]{2}:[0-9,A-Z]{2})/x; 182 $ret{hostname_fq} = $1 if(defined($1)); 183 $ret{ipv4_address} = $2 if(defined($2)); 184 $ret{mac_address} = $3 if(defined($3)); 186 if ( $cmd_arp =~ m{ (\S*) \s \( ( $RE_IPv4_ADDRESS ) \) \s at \s ( $RE_MAC_ADDRESS ) }xms ) { 187 ( $ret{hostname_fq}, $ret{ipv4_address}, $ret{mac_address} ) = ($1, $2, $3); 188 } 185 189 186 190 # resultat de la commande host si le parametre est ip 187 191 # 250.66.254.194.in-addr.arpa domain name pointer legihp2100.hmg.inpg.fr. 188 my $cmd_host = `host $param_ip_or_host 2> /dev/null`;192 my $cmd_host = `host $param_ip_or_host 2> /dev/null`; 189 193 chomp $cmd_host; 190 $cmd_host =~ m/domain \s name \s pointer \s (\S+) \.$/x; 191 $ret{hostname_fq} = $1 if defined $1; 194 if ( $cmd_host =~ m/domain \s name \s pointer \s (\S+) \.$/xms ) { 195 $ret{hostname_fq} = $1; 196 } 192 197 193 198 # resultat de la commande host si parametre est hostname 194 199 # tech7meylan.hmg.inpg.fr has address 194.254.66.240 195 $cmd_host =~ m/(\S*) \s has \s address \s ( [0-9]{1,3} \. [0-9]{1,3} \. [0-9]{1,3} \. [0-9]{1,3} )$/x; 196 $ret{hostname_fq} = $1 if defined $1; 197 $ret{ipv4_address} = $2 if defined $2; 198 199 $cmd_host =~ m/ \b ([0-9]{1,3}) \. ([0-9]{1,3}) \. ([0-9]{1,3}) \. ([0-9]{1,3}) \. in-addr \. arpa \s/x; 200 $ret{ipv4_address} = "$4.$3.$2.$1" if defined $1 and defined $2 and defined $3 and defined $4; 201 $ret{hostname_fq} = $param_ip_or_host if not defined $1 and $ret{hostname_fq} eq 'unknow'; 200 if ( $cmd_host =~ m/(\S*) \s has \s address \s ( $RE_IPv4_ADDRESS )$/xms ) { 201 ( $ret{hostname_fq}, $ret{ipv4_address} ) = ($1, $2); 202 } 203 204 if ( $cmd_host =~ m/ \b ( $RE_IPv4_ADDRESS ) \. in-addr \. arpa \s/xms ) { 205 $ret{ipv4_address} = $1; 206 } 207 #$ret{hostname_fq} = $param_ip_or_host if not defined $1 and $ret{hostname_fq} eq 'unknow'; 202 208 203 209 unless ($ret{mac_address} eq 'unknow') { 204 210 my @paquets = (); 205 211 foreach ( split m/ : /x, $ret{mac_address} ) { 206 my @chars = split m//x , uc("00$_");212 my @chars = split m//xms, uc("00$_"); 207 213 push @paquets, "$chars[-2]$chars[-1]"; 208 214 }
Note: See TracChangeset
for help on using the changeset viewer.