From: André Frimberger Date: Sat, 18 Oct 2014 16:01:31 +0000 (+0200) Subject: Add ipv6 support. X-Git-Tag: v1.0.4~1^2~1 X-Git-Url: http://git.neszt.hu/?a=commitdiff_plain;h=aae7176cc57facce6b4f3e39bca11a61f86683a2;p=Dyndns%2F.git Add ipv6 support. --- diff --git a/src/Dyndns/Helper.php b/src/Dyndns/Helper.php old mode 100644 new mode 100755 index 12adaf9..8c2b316 --- a/src/Dyndns/Helper.php +++ b/src/Dyndns/Helper.php @@ -15,7 +15,7 @@ class Helper */ public static function checkValidIp($ip) { - return (ip2long($ip) !== false); + return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) || filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); } /** diff --git a/src/Dyndns/Hosts.php b/src/Dyndns/Hosts.php old mode 100644 new mode 100755 index d448ed7..d06dcc7 --- a/src/Dyndns/Hosts.php +++ b/src/Dyndns/Hosts.php @@ -171,8 +171,17 @@ class Hosts fwrite($fh, "server $server\n"); fwrite($fh, "zone $zone\n"); foreach ($this->updates as $host => $ip) { - fwrite($fh, "update delete $host A\n"); - fwrite($fh, "update add $host $ttl A $ip\n"); + $recType = "unknown record type"; + + if( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ){ + $recType = "A"; + } + + if( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ){ + $recType = "AAAA"; + } + fwrite($fh, "update delete $host $recType\n"); + fwrite($fh, "update add $host $ttl $recType $ip\n"); } fwrite($fh, "send\n"); fclose($fh);