Zend - The PHP Company




Miscellaneous

Add Code


dhs.org DNS Updater  

Type: code fragment
Added by: rev0
Entered: 30/05/2000
Last modified: 08/12/1999
Rating: - (fewer than 3 votes)
Views: 5580
Use this code to connect to the dhs servers and update your ip address and other information (useful with another standalone script running from cron to check for a change in ip over roadrunner or dsl)


<?

// Usage:
//
// first argument is your hostname (i.e. if you use snoopy.2y.net this argument should be snoopy)
// second is the dhs domain (i.e. 2y.net from example above.)
// third is the ip address you want to update it with, leave blank to use the current ip
// finally, fourth and fifth arguments are the username and password to logon to the dhs servers.

function update_dhs_host($dhshostname$dhsdomain$ipaddr$user$pass) {

        
$mxhost $dhshostname.".".$dhsdomain;
        
$offlineurl "";
        
$cloak="N";
        
$cloak_title="";

        
# If no ip is given, get and use the current one.
        
if (trim($ipaddr)=="") {
                
exec("/sbin/ifconfig eth0 | grep inet | cut -d " " -f 12 | cut -b 6-"$ip);
                
$ipaddr trim($ip[0]);
        }

        
# Open connection to the dhs members web server to update host
        
$fp fsockopen("members.dhs.org"80$errno$errstr30);

        if (
$fp) {
                
$postdata "updatetype=Online&type=4&hostscmd=edit&hostscmdstage=2";
                
$postdata.= "&ip=$ipaddr&mx=$mxhost&offline_url=$offlineurl&cloak=$cloak";
                
$postdata.= "&cloak_title=$cloak_title&domain=$dhsdomain&hostname=$dhshostname";
                
$length strlen($postdata);
        
                
$requri "POST /nic/hosts HTTP/1.0n";
                
$requri.= "Host: members.dhs.orgn";
                
$requri.= "Authorization: Basic ".base64_encode("$user:$pass")."n";
                
$requri.= "Content-type: application/x-www-form-urlencodedn";
                
$requri.= "Content-length: $lengthnn";
                
$requri.= "$postdatan";        
        
                
fputs($fp$requri);
        
                
# Get the response from the dhs server.
                
while(!feof($fp)) 
                        
$buffer.=fgets($fp,1024);

                
fclose($fp);

                
# Check to see if the update was completed.
                
if (stristr($buffer"Updating ip on")) { 
                        return 
true;
                } else {

                        
# if not, check to see if the reason was because we already
                        
if(stristr($buffer"The update has already been done previously.")) {
                                return 
true;
                        
# if none of these are true, there was a problem, return false
                        
} else {
                                return 
false;
                        }
                }

        
# The connection wasn't made, return false.
        
} else {
                return 
false;
        }
}

?>


Usage Example




Rate This Script





Search



This Category All Categories