@@ -29,7 +29,7 @@ function __construct($argv)
2929 $ hostname = (string ) $ argv [3 ]; // example: example.com.uk---sundomain.example1.com---example2.com
3030 $ this ->ip = (string ) $ argv [4 ];
3131
32- $ this ->validateIpV4 ($ this ->ip );
32+ $ this ->validateIp ($ this ->ip );
3333
3434 $ arHost = explode ('--- ' , $ hostname );
3535 if (empty ($ arHost )) {
@@ -61,9 +61,9 @@ function makeUpdateDNS()
6161 $ this ->badParam ('empty host list ' );
6262 }
6363
64- foreach ($ this ->hostList as $ arHost ) {
64+ foreach ($ this ->hostList as $ arHost ) {
6565 $ post = [
66- 'type ' => ' A ' ,
66+ 'type ' => $ this -> getZoneTypeByIp ( $ this -> ip ) ,
6767 'name ' => $ arHost ['fullname ' ],
6868 'content ' => $ this ->ip ,
6969 'ttl ' => 1 ,
@@ -85,14 +85,25 @@ function badParam($msg = '')
8585 exit ();
8686 }
8787
88- function validateIpV4 ($ ip )
88+ function validateIp ($ ip )
8989 {
90- if (!filter_var ($ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 )) {
91- $ this ->badParam ('invalid ip-address, only ipv4 ' );
90+ if (!filter_var ($ ip , FILTER_VALIDATE_IP )) {
91+ $ this ->badParam ('invalid ip-address ' );
9292 }
9393 return true ;
9494 }
9595
96+ /*
97+ * IPv4 = zone A, IPv6 = zone AAAA
98+ * @link https://www.cloudflare.com/en-au/learning/dns/dns-records/dns-a-record/
99+ */
100+ function getZoneTypeByIp ($ ip ) {
101+ if (filter_var ($ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 )) {
102+ return 'AAAA ' ;
103+ }
104+ return 'A ' ;
105+ }
106+
96107 /**
97108 * Set ZoneID for each hosts
98109 */
0 commit comments