{"id":58,"date":"2008-12-18T18:59:55","date_gmt":"2008-12-19T00:59:55","guid":{"rendered":"http:\/\/xux.in\/blog\/?p=58"},"modified":"2021-06-19T19:43:19","modified_gmt":"2021-06-20T01:43:19","slug":"php-editdns-updater-for-linux","status":"publish","type":"post","link":"http:\/\/xux.in\/blog\/post\/php-editdns-updater-for-linux\/","title":{"rendered":"PHP EditDNS Updater for Linux"},"content":{"rendered":"<p>This is a simple PHP script which will update your dynamic DNS records using EditDNS.<\/p>\n<p>Features:<br \/>\n&#8211; You can configure as many records as you want.<br \/>\n&#8211; Supports HTTP and HTTPS.<br \/>\n&#8211; For PHP 4x and higher compiled with sockets.<br \/>\n&#8211; Simple validation.<\/p>\n<p>Here is the code: (editdns.php)<\/p>\n<pre lang=\"php\">#!\/usr\/bin\/php -q\n&lt;?php\n\n$port = 443; \/\/ use 80 if you dont wanna use SSL\n\/\/ add as many arrays as you want, first element is the record\n\/\/ and the second is the password\n\/\/ $data[] = array('myrecord1.domain.com','mypass1');\n\/\/ $data[] = array('myrecord2.domain.com','mypass2');\n\/\/ ... etc etc etc ;)\n$data[] = array('somerecord.resolveme.com','blahblah123');\n$sleep = 1; \/\/ seconds we should sleep before updating another record\n\n\/\/ main loop\nif (!is_array($data)) die(\"Nothing to do\\n\");\nforeach ($data as $v) {\n  echo \"Updating $v[0] ... \";\n  if(_send($port,\"p=$v[1]&amp;r=$v[0]\")) echo \"[OK]\\n\";\n  sleep($sleep);\n}\n\nfunction _send($port=443,$args=\"\") {\n  if ($port == 443) $proto = \"ssl\";\n  else $proto = \"http\";\n  $fp = fsockopen(\"$proto:\/\/dyndns.editdns.net\",$port,$errno,$errstr,10);\n  if (!$fp) die(\"\\nCouldn't establish connection\\n\");\n  $out = \"POST \/api\/dynLinux.php HTTP\/1.0\\r\\n\";\n  $out .= \"Host: dyndns.editdns.net\\r\\n\";\n  $out .= \"Content-Type: application\/x-www-form-urlencoded\\r\\n\";\n  $out .= \"Content-Length: \".strlen($args).\"\\r\\n\";\n  $out .= \"Connection: Close\\r\\n\\r\\n\";\n  $out .= $args;\n  \/\/echo $out;\n  fwrite($fp, $out);\n  while (!feof($fp)) {\n    $res .= fgets($fp,1024);\n  }\n  fclose($fp);\n  $parts = explode(\"\\r\\n\\r\\n\",trim($res));\n  \/\/print_r($parts);\n  \/\/ checking output\n  if (preg_match(\"\/record has been updated|record already exists\/i\",$parts[1])) return 1;\n  \/\/ anything else should be an error\n  echo \"[ERROR]\\n\\t$parts[1]\\n\";\n  return 0;\n}\n\n?&gt;\n<\/pre>\n<p>Save it, chmod +x and play with it.<\/p>\n<p>Old sources:<br \/>\n<a href=\"http:\/\/forums.nerdie.net\/showthread.php?t=616\">http:\/\/forums.nerdie.net\/showthread.php?t=616<\/a><br \/>\n<a href=\"http:\/\/xux.in\/blog\/post\/ip-updater-for-editdnsnet\/\">http:\/\/xux.in\/blog\/post\/ip-updater-for-editdnsnet\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a simple PHP script which will update your dynamic DNS records using EditDNS. Features: &#8211; You can configure as many records as you want. &#8211; Supports HTTP and HTTPS. &#8211; For PHP 4x and higher compiled with sockets. &#8211; Simple validation. Here is the code: (editdns.php) #!\/usr\/bin\/php -q &lt;?php $port = 443; \/\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31,8,5],"tags":[18,15],"class_list":["post-58","post","type-post","status-publish","format-standard","hentry","category-code","category-linux","category-software","tag-editdns","tag-php"],"_links":{"self":[{"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/posts\/58","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/comments?post=58"}],"version-history":[{"count":5,"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/posts\/58\/revisions"}],"predecessor-version":[{"id":149,"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/posts\/58\/revisions\/149"}],"wp:attachment":[{"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/media?parent=58"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/categories?post=58"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/tags?post=58"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}