public static function isHostnameIP($hostname)
  {
    // IP-literal: encased in square brackets
    // we match starting [ character followed by non ] characters followed by ] character as last character in hostname
    if(preg_match('/^\[[^\]]\]$/',$hostname)){
      // ok its an IP-literal, we do not parse the literal to see if its valid
      return true;
    }
    // IPv4 in decimal
    if(preg_match('/^[0-9]+$/',$hostname)){
      // ok its a number
      // lets see if its in the 32bit range
      $ip4_hex=base_convert($hostname, 10, 16);
      if(strlen($ip4_hex)<=8){
        // ok, hex representation is less than 9 chars, so thats max FFFFFFFF
        return true;
      }
    }
    $ip_parts=Array();
    if(!preg_match('/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/',$hostname,$ip_parts)){
      return false;
    }
    // check if each block is in byte range (hard to test with regex)
    for($j=1;$j<=4;$j++){
      if(($ip_parts[$j]>255) || ($ip_parts[$j]<0)){
        return false;
      }
    }
    return true;
  }