Changeset 68
- Timestamp:
- Nov 2, 2010, 11:24:46 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r67 r68 18 18 use NetAddr::IP; 19 19 use Getopt::Long; 20 use Socket; 20 21 21 22 # apt-get install snmp fping libnet-cidr-lite-perl libnet-netmask-perl libnet-snmp-perl libnetaddr-ip-perl libyaml-perl 22 # libcrypt-des-perl libcrypt-hcesha-perl libdigest-hmac-perl 23 # libcrypt-des-perl libcrypt-hcesha-perl libdigest-hmac-perl 23 24 # arping fping bind9-host arpwatch 24 25 … … 79 80 J4120A => { model => 'HP1600M', match => 'HP J4120A ProCurve Switch 1600M' }, 80 81 J9029A => { model => 'HP1800-8G', match => 'PROCURVE J9029A' }, 82 J9449A => { model => 'HP1810-8G', match => 'HP ProCurve 1810G - 8 GE' }, 81 83 J4093A => { model => 'HP2424M', match => 'HP J4093A ProCurve Switch 2424M' }, 82 84 J4813A => { model => 'HP2524', match => 'HP J4813A ProCurve Switch 2524' }, … … 92 94 93 95 Readonly my %OID_NUMBER => ( 94 sysDescription => '1.3.6.1.2.1.1.1.0', 95 sysName => '1.3.6.1.2.1.1.5.0', 96 sysContact => '1.3.6.1.2.1.1.4.0', 97 sysLocation => '1.3.6.1.2.1.1.6.0', 98 ifMtu => '1.3.6.1.2.1.2.2.1.4', 99 ifSpeed => '1.3.6.1.2.1.2.2.1.5', 96 sysDescription => '1.3.6.1.2.1.1.1.0', 97 sysName => '1.3.6.1.2.1.1.5.0', 98 sysContact => '1.3.6.1.2.1.1.4.0', 99 sysLocation => '1.3.6.1.2.1.1.6.0', 100 100 ); 101 101 … … 139 139 # fast ping dont l'objectif est de remplir la table arp de la machine 140 140 sub fastping { 141 system "fping -c 1 @_ >/dev/null 2>&1"; 141 # Launch this command without waiting... 142 system "fping -c 1 @_ >/dev/null 2>&1 &"; 142 143 return; 143 144 } … … 169 170 170 171 # my $cmdarping = `arping -c 1 -w 1 -rR $param 2>/dev/null`; 171 if ( not $param_ip_or_host =~ m/^\d+ \. \d+ \. \d+ \. \d+$/xms ) { 172 $param_ip_or_host =~ s/ \. .* //xms; 173 } 172 # if ( not $param_ip_or_host =~ m/^\d+ \. \d+ \. \d+ \. \d+$/xms ) { 173 # $param_ip_or_host =~ s/ \. .* //xms; 174 # } 175 176 #my $dns_resolver = Net::DNS::Resolver->new; 177 #my $dns_answer = $dns_resolver->query($param_ip_or_host); 178 #if ($dns_answer) { 179 # $ret{ipv4_address} = $dns_answer->address; 180 # } 181 182 # perl -MSocket -E 'say inet_ntoa(scalar gethostbyname("tech7meylan.hmg.inpg.fr"))' 183 my $packed_ip = scalar gethostbyname($param_ip_or_host); 184 return %ret if not defined $packed_ip; 185 $ret{ipv4_address} = inet_ntoa($packed_ip); 186 187 # perl -MSocket -E 'say scalar gethostbyaddr(inet_aton("194.254.66.240"), AF_INET)' 188 my $hostname_fq = scalar gethostbyaddr($packed_ip, AF_INET); 189 # return %ret if not defined $hostname_fq; 190 $ret{hostname_fq} = $hostname_fq if defined $hostname_fq; 191 192 #print "DEBUG : $param_ip_or_host -- $ret{ipv4_address} -- $hostname_fq \n"; 174 193 175 194 # controler que arpwatch tourne ! … … 179 198 # my $cmd = "grep -e '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/arp.dat | sort +2rn | head -1"; 180 199 # my $cmd = "grep -he '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/*.dat | sort +2rn | head -1"; 181 my $cmd = q{grep -he '\b} . $param_ip_or_host . q{\b' } . "/var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1"; 200 201 ### BOGUE ICI 202 ### FAIRE LE GREP SUR L'IP ! 203 204 # my $cmd = q{grep -he '\b} . $param_ip_or_host . q{\b' } . "/var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1"; 205 my $cmd = q{grep -he '\b} . $ret{ipv4_address} . q{\b' } . "/var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1"; 182 206 my $cmd_arpwatch = shell_command $cmd; 183 207 my ($arp, $ip, $timestamp, $host) = split m/ \s+ /xms, $cmd_arpwatch; 184 208 185 $ret{ipv4_address} = $ip if $ip;209 # $ret{ipv4_address} = $ip if $ip; 186 210 $ret{mac_address} = $arp if $arp; 187 211 $ret{timestamp} = $timestamp if $timestamp; … … 204 228 # resultat de la commande host si le parametre est ip 205 229 # 250.66.254.194.in-addr.arpa domain name pointer legihp2100.hmg.inpg.fr. 206 my $cmd_host = shell_command "host $param_ip_or_host";207 if ( $cmd_host =~ m/domain \s name \s pointer \s (\S+) \.$/xms ) {208 $ret{hostname_fq} = $1;209 }230 # my $cmd_host = shell_command "host $param_ip_or_host"; 231 # if ( $cmd_host =~ m/domain \s name \s pointer \s (\S+) \.$/xms ) { 232 # $ret{hostname_fq} = $1; 233 # } 210 234 211 235 # resultat de la commande host si parametre est hostname 212 236 # tech7meylan.hmg.inpg.fr has address 194.254.66.240 213 if ( $cmd_host =~ m/(\S*) \s has \s address \s ( $RE_IPv4_ADDRESS )$/xms ) {214 ( $ret{hostname_fq}, $ret{ipv4_address} ) = ($1, $2);215 }237 # if ( $cmd_host =~ m/(\S*) \s has \s address \s ( $RE_IPv4_ADDRESS )$/xms ) { 238 # ( $ret{hostname_fq}, $ret{ipv4_address} ) = ($1, $2); 239 # } 216 240 217 241 # Connerie ! … … 416 440 my $swport = $result->{$research}; 417 441 442 #print "DEBUG $arp $swport -- $sw->{hostname} \n"; 443 if ( $sw->{hostname} eq 'sw10-batE1-3s.hmg.priv' and $swport == 19 ) { $swport = 20; print "DEBUG $swport -- $sw->{hostname} \n";} 444 if ( $sw->{hostname} eq 'sw8-batE1-3s.hmg.priv' and $swport == 23 ) { $swport = 24; print "DEBUG $swport -- $sw->{hostname} \n";} 445 # if ( $sw->{hostname} eq 'sw10-batE1-3s.hmg.priv' ) { print "DEBUG $swport -- $sw->{hostname} \n";} 446 # if ( $sw->{hostname} eq 'sw8-batE1-3s.hmg.priv' ) { print "DEBUG $swport -- $sw->{hostname} \n";} 447 418 448 $ret->{$sw->{hostname}} = {}; 419 449 $ret->{$sw->{hostname}}{hostname} = $sw->{hostname}; … … 562 592 klask searchdb computer 563 593 klask search computer 594 klask search-mac-on-switch switch mac_addr 564 595 565 596 klask enable switch port … … 1232 1263 1233 1264 $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address}); # find port on all switch 1265 #my @l = (); 1266 #for my $c ( keys %{$where{$resol_arp{ipv4_address}}} ) { 1267 #push @l, "$c -+ "; #$where{$resol_arp{ipv4_address}}->{$c}{hostname}; 1268 #} 1269 #print "DEBUG $one_computer $resol_arp{ipv4_address} $resol_arp{mac_address} --- @l\n"; 1234 1270 1235 1271 $db_switch_ip_hostname{$resol_arp{ipv4_address}} = $resol_arp{hostname_fq}; … … 1251 1287 1252 1288 my $switch = $where{$ip}->{$switch_detected}; 1289 #print "DEBUG1 : $db_switch_ip_hostname{$ip} / $switch->{hostname} : $switch->{port}\n" if $switch->{hostname} =~ m/sw3-batA0-3s/; 1253 1290 1254 1291 next if $switch->{port} eq '0'; … … 1258 1295 $db_switch_link_with{ $db_switch_ip_hostname{$ip} } ||= {}; 1259 1296 $db_switch_link_with{ $db_switch_ip_hostname{$ip} }->{ $switch->{hostname} } = $switch->{port}; 1297 #print "DEBUG : $db_switch_ip_hostname{$ip} / $switch->{hostname} : $switch->{port}\n" if $switch->{hostname} !~ m/sw3-batA0-3s/; 1260 1298 } 1261 1299
Note: See TracChangeset
for help on using the changeset viewer.