Miscellaneous
|
|
|
|
<?
// 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, $errstr, 30);
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
|
|
|
|