From aae7176cc57facce6b4f3e39bca11a61f86683a2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Frimberger?= Date: Sat, 18 Oct 2014 18:01:31 +0200 Subject: [PATCH] Add ipv6 support. --- src/Dyndns/Helper.php | 2 +- src/Dyndns/Hosts.php | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) mode change 100644 => 100755 src/Dyndns/Helper.php mode change 100644 => 100755 src/Dyndns/Hosts.php 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); -- 2.1.4