Skip to content

Instantly share code, notes, and snippets.

@RichieChill
Last active August 29, 2015 14:24
Show Gist options
  • Save RichieChill/a286479a8a144082afa5 to your computer and use it in GitHub Desktop.
Save RichieChill/a286479a8a144082afa5 to your computer and use it in GitHub Desktop.
Update a domain's IP address using namecheap.com's dynamic DNS service.
#!/usr/bin/env php
<?php
/**
* Update the IP of a dynamic DNS domain from Namecheap.com.
*
* Assign this script to a cron job or run it from a terminal manually.
* It checks the current public (Internet) address and updates the domain to point to it.
*
* @see [How do I enable Dynamic DNS for a domain?](https://www.namecheap.com/support/knowledgebase/article.aspx/595/11/how-do-i-enable-dynamic-dns-for-a-domain)
* @see [How do I use the browser to dynamically update host's IP?](https://www.namecheap.com/support/knowledgebase/article.aspx/29/11/how-do-i-use-the-browser-to-dynamically-update-hosts-ip)
*
*
* @author Richard Chillington
* @link https://gist.github.com/rchillington/a286479a8a144082afa5
* @license MIT
*/
// Change these to your settings.
$ddSubdomain = 'www';
$ddDomain = '';
$ddPassword = '';
// Can also try, "http://ipecho.net/plain".
$ipHost = 'http://ipinfo.io/ip';
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $ipHost );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
$ddIp = curl_exec( $ch );
curl_close( $ch );
preg_match( '/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/', $ddIp, $matches );
if( $matches[0] )
{
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, 'https://dynamicdns.park-your-domain.com/update?host=' . $ddSubdomain . '&domain=' . $ddDomain . '&password=' . $ddPassword . '&ip=' . $ddIp );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
$result = curl_exec( $ch );
curl_close( $ch );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment