Changeset 52 for trunk


Ignore:
Timestamp:
Jul 24, 2009, 12:53:46 AM (15 years ago)
Author:
g7moreau
Message:
  • Suppress perlcritic warnng level 3 Backtrick usage. Replace by open, '-|' This commit has not be validate ont real situation
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r51 r52  
    99
    1010use Readonly;
     11use Filehandle;
    1112use Net::SNMP;
    1213#use YAML;
     
    139140   }
    140141
     142sub 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
    141153###
    142154# donne l'@ ip, dns, arp en fonction du dns OU de l'ip
     
    164176   # my $cmd = "grep  -he '".'\b'."$param_ip_or_host".'\b'."' /var/lib/arpwatch/*.dat | sort +2rn | head -1";
    165177   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;
    169180
    170181   $ret{ipv4_address} = $ip        if $ip;
     
    182193   # tech7meylan.hmg.inpg.fr (194.254.66.240) at 00:14:22:45:28:A9 [ether] on eth0
    183194   # 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";
    186196   if ( $cmd_arp =~ m{ (\S*) \s \( ( $RE_IPv4_ADDRESS ) \) \s at \s ( $RE_MAC_ADDRESS ) }xms ) {
    187197      ( $ret{hostname_fq}, $ret{ipv4_address}, $ret{mac_address} )  = ($1, $2, $3);
     
    190200   # resultat de la commande host si le parametre est ip
    191201   # 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";
    194203   if ( $cmd_host =~ m/domain \s name \s pointer \s (\S+) \.$/xms ) {
    195204      $ret{hostname_fq} = $1;
Note: See TracChangeset for help on using the changeset viewer.