Aytos o odigos edo tha prepei na diavastei oxi san vima pros vima odigies alla gia na pareis idees tou pos mporeis na xrisimopihseis thn Dynamic ADSL gia na steiseis ypiresies…
Gia paradigma kai to idio to Linuxer aythn thn stigmh (06/10/2005) vriskete se mia ADSL grammh..
Gia na mporeite na mas vriskete akomh kai an alazei h ip kanopume xrhsh ton dorean DNS tou xname.org
To parakato script kanei ta ekshs:
Koitaei to modem router me snmp kai pernei thn trexousa IP an einai diaforetikh apo aythn pou eixe filaksh proigoumenos thn formarh se xml kai thn stelnei sto xname.org gia na ananeosh thn ip sto dns…
Xreisimpopihsa snmp gia na vlepo thn IP tou router gia dio logous.
O enas einai oti eksanagazo to router na mhn adranish kai o deyteros giati diaforetika tha eprepe na kano xrhsh kapias ypiresias opos h whatismyip.com filtrarontas thn selida html pou parexei kati pou omos den einai kai toso sigouro mias kai mporei aproidopihta na alaksh ayth h selida…
To script ayto exei mpei se ena cron job kathe 10 lepta …
O router exei rithmistei oste otan ziththei h porta 80 na kanei redirect (PAT) sto pc (sthn periptosh tou Linuxer ena Xbox 😉 ) pou trexei ton web server..
<?php
/*
Reload xname.org dns zone
Author: Panagiotis Skarvelis <sl45sms@yahoo.gr>
Date: 8/9/2005
Version: 1.0
This program, including associated files, is free software. You may
distribute it and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either Version 2 of
the license, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//CONFIG VALS
$RouterAddress = “xxx.xxx.xxx.xxx”;
$Community = “public”;
$IPindex = 0;
$tmpoldmydslip = “/tmp/mydslip”; //must have write access
$user = “yourusername”;
$password = “yourpassword”;
$zone = “linuxer.gr”;
$name = “www”;
///////////////////////////////////////////////////////////////////////////////////////////////////
$havenewip = false;
$debug = false;
//get the ip from snmp
$tmp = snmpwalk($RouterAddress, $Community, “ip.ipAddrTable.ipAddrEntry.ipAdEntAddr”);
$mydslip= substr($tmp[$IPindex],11);
echo “My dsl ip is “.$mydslip.”\r\n”;
//check if don’t have connection
//two posibilities:
//have 0.0.0.0 as ip
if ($mydslip==”0.0.0.0″) die(“Not conected to network”);
//don\’t have a valid ip address (like a message say timeout)
if (!ereg(“^[0-9]{2,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$”, $mydslip)) die(“Have problematic ip”);
//open tmp file for reading
if (!$handle = fopen($tmpoldmydslip, ‘a+’)) {
echo “Cannot open or create file ($oldmydslip)”;
exit;
}
if (filesize($tmpoldmydslip))
$oldmydslip = fread($handle,filesize($tmpoldmydslip));else $oldmydslip=””;
if ($mydslip!=$oldmydslip)
{
echo “Save new ip to file\r\n”;
fseek($handle, 0);
ftruncate($handle, ‘0’);
// Write mydslip to our tmp file.
if (fwrite($handle, $mydslip) === FALSE) {
echo “Cannot write to file ($filename)”;
exit;
}
$havenewip = true;
}
fclose($handle);
//if have new ip then
if ($havenewip){
echo “Send xml to xname.org”;
//xebian have problems with xmlrpc so i prepare and send xml by self!
if ($debug) echo “Setup DNS:”;
$xmlrqs = “<?xml version=\”1.0\” encoding=\”UTF-8\”?>
<methodCall>
<methodName>xname.updateArecord</methodName>
<params>
<param>
<value><struct>
<member><name>user</name>
<value><string>”.$user.”</string></value>
</member>
<member><name>password</name>
<value><string>”.$password.”</string></value>
</member>
<member><name>zone</name>
<value><string>”.$zone.”</string></value>
</member>
<member><name>recordname</name>
<value><string>”.$name.”</string></value>
</member>
<member><name>oldaddress</name>
<value><string>*</string></value>
</member>
<member><name>newaddress</name>
<value><string>”.$mydslip.”</string></value>
</member>
<member><name>name</name>
<value><string>”.$name.”</string></value>
</member>
<member><name>ttl</name>
<value><string>600</string></value>
</member>
</struct></value>
</param>
</params>
</methodCall>
“;
if ($debug) echo $xmlrqs.”\r\n”;
$sock = fsockopen(“www.xname.org”, 80, $errno, $errstr, 30);
if (!$sock) die(“$errstr ($errno)”);
fputs($sock, “POST /xmlrpc.php HTTP/1.0\r\n”);
fputs($sock, “Host: www.xname.org\r\n”);
fputs($sock, “Content-type: application/x-www-url-encoded\r\n”);
fputs($sock, “Content-length: ” . strlen($xmlrqs) . “\r\n”);
fputs($sock, “Accept: */*\r\n”);
fputs($sock, “\r\n”);
fputs($sock, “$xmlrqs\r\n”);
fputs($sock, “\r\n”);
# Headers
while ($str = trim(fgets($sock, 4096)));
echo “$str\n”;
# Body
$body=””;
while (!feof($sock))
$body.=fgets($sock, 4096);
fclose($sock);
if ($debug) echo “Get this responce:”.$body.”\r\n”;
echo “done.\n”;
/*
//or you can use this more elegand code if you use
// http://phpxmlrpc.sourceforge.net/
include(“xmlrpc.inc”);
$req = xmlrpc_encode(
array(
“user” => $user,
“password” => $password,
“zone” => $zone,
“recordname” => $name,
“oldaddress” => “*”,
“newaddress” => $mydslip,
“name” => $name,
“ttl” => “600”
)
);
$f=new xmlrpcmsg(‘xname.updateArecord’,array($req));
print “<pre>” . $f->serialize() . “</pre>”;
$c=new xmlrpc_client(“/xmlrpc.php”, “www.xname.org”, 0);
$c->setDebug(0);
$r=$c->send($f, 0, “http”);
if (!$r) { die(“send failed”); }
$v=$r->value();
if (!$r->faultCode())
// print “State number “. $HTTP_POST_VARS[“stateno”] . ” is ” . $v->scalarval() . “<BR>”;
print “I got this value back” . $r->serialize(). “\n”;
else print ” Fault Code: ” . $r->faultCode() . ” Reason \'” .$r->faultString().”\n”;
*/
}
?>