Changeset 52
- Timestamp:
- Jul 24, 2009, 12:53:46 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r51 r52 9 9 10 10 use Readonly; 11 use Filehandle; 11 12 use Net::SNMP; 12 13 #use YAML; … … 139 140 } 140 141 142 sub shell_command { 143 my $cmd = shift; 144 145 my $fh = new Filehandle; 146 open $fh, '-|', "$cmd" or die "Can't exec $cmd\n"; 147 my $result = <$fh>; 148 close $fh; 149 chomp $result; 150 return $result; 151 } 152 141 153 ### 142 154 # donne l'@ ip, dns, arp en fonction du dns OU de l'ip … … 164 176 # my $cmd = "grep -he '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/*.dat | sort +2rn | head -1"; 165 177 my $cmd = "grep -he '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/$interface.dat | sort -rn -k 3,3 | head -1"; 166 my $cmd_arpwatch = `$cmd`; 167 chomp $cmd_arpwatch; 168 my ($arp, $ip, $timestamp, $host) = split m/ \s+ /x, $cmd_arpwatch; 178 my $cmd_arpwatch = shell_command $cmd; 179 my ($arp, $ip, $timestamp, $host) = split m/ \s+ /xms, $cmd_arpwatch; 169 180 170 181 $ret{ipv4_address} = $ip if $ip; … … 182 193 # tech7meylan.hmg.inpg.fr (194.254.66.240) at 00:14:22:45:28:A9 [ether] on eth0 183 194 # sw2-batF0-legi.hmg.priv (192.168.22.112) at 00:30:c1:76:9c:01 [ether] on eth0.37 184 my $cmd_arp = `arp -a $param_ip_or_host 2> /dev/null`; 185 chomp $cmd_arp; 195 my $cmd_arp = shell_command "arp -a $param_ip_or_host"; 186 196 if ( $cmd_arp =~ m{ (\S*) \s \( ( $RE_IPv4_ADDRESS ) \) \s at \s ( $RE_MAC_ADDRESS ) }xms ) { 187 197 ( $ret{hostname_fq}, $ret{ipv4_address}, $ret{mac_address} ) = ($1, $2, $3); … … 190 200 # resultat de la commande host si le parametre est ip 191 201 # 250.66.254.194.in-addr.arpa domain name pointer legihp2100.hmg.inpg.fr. 192 my $cmd_host = `host $param_ip_or_host 2> /dev/null`; 193 chomp $cmd_host; 202 my $cmd_host = shell_command "host $param_ip_or_host"; 194 203 if ( $cmd_host =~ m/domain \s name \s pointer \s (\S+) \.$/xms ) { 195 204 $ret{hostname_fq} = $1;
Note: See TracChangeset
for help on using the changeset viewer.