GratisDNS update script
April 8, 2011
As the dyndns update script, I now also got one for gratisdns.dk
<?php $username = "gratisdns user"; $password = "gratisdns pass"; $domains = array("domain.com"); $hosts = array("host.domain.com"); $myIP; function getip() { global $myIP; $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12"); curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2); curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1); curl_setopt($curl_handle,CURLOPT_URL, "http://checkip.dyndns.org/"); $buffer = curl_exec($curl_handle); if(curl_errno($curl_handle)) { echo 'Curl error: ' . curl_error($curl_handle); return -1; } else { if (empty($buffer)) { return -1; } else { $myIP = substr($buffer, 76, -16); $myFile = "store"; $theData = ""; if (file_exists($myFile)) { $fh = fopen($myFile, 'r'); $theData = fread($fh, filesize($myFile)); fclose($fh); } if ($theData != $myIP) { $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = $myIP; fwrite($fh, $stringData); fclose($fh); return 1; } else { return 0; } } } curl_close($curl_handle); } $status = getip(); if ($status == 1) { echo "Updating:"; for($i = 0; $i < count($domains); $i++) { $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12"); curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2); curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1); curl_setopt($curl_handle,CURLOPT_URL, "https://ssl.gratisdns.dk/ddns.phtml?u=" . $username . "&p=" . $password . "&d=" . $domains[$i] . "&h=" . $hosts[$i] . "&i=" . myIP); $buffer = curl_exec($curl_handle); if(curl_errno($curl_handle)) { echo 'Curl error: ' . curl_error($curl_handle); } else { if (empty($buffer)) { print "No connection."; } else { print "\n\t" . $domains[$i] . " - " . $buffer; } } curl_close($curl_handle); } } else if ($status == 0) { echo "No update needed."; } else { echo "Could not connect to checkip.dyndns.org"; } ?>