You are here

function _autoban_digexec in Automatic IP ban (Autoban) 7

Alternate function getting Internet host by IP address using dig command.

Parameters

string $ip: IP address.

Return value

string Internet host.

File

./autoban.module, line 998
Main file for autoban module.

Code

function _autoban_digexec($ip) {
  $string = '';
  exec("dig +short +retry=1 +timeout=1 +tries=1 -x {$ip} 2>&1", $output, $retval);
  if ($retval != 0) {

    // there was an error performing the command
    return FALSE;
  }
  else {
    $x = 0;
    while ($x < sizeof($output)) {
      $string .= $output[$x];
      $x++;
    }
  }
  if (empty($string)) {
    $string = $ip;
  }
  else {

    //remove the trailing dot
    $string = substr($string, 0, -1);
  }
  return $string;
}