URL: https://linuxfr.org/forums/programmation-php/posts/phpupdate Title: phpupdate Authors: EPROM Date: 2007年03月16日T14:10:26+01:00 Tags: Score: 0 Bonjour, j'essaye de greffer un script à ma page d'index apache de manière à rafraîchir l'IP de ma neuf box quand celle ci a une adresse IP WAN qui change. Le script c'est celui là:
<?PHP #version 0.02b 07/04/2003 # get-ip2 was originally written for a Dynalink RTA300W but the router died, It was then replaced # and the wireless part of the router was faulty so I gave up and reconfigured it for use with an # Alcatel Speedtouch Home that was upgraded to a Pro. # It should work on most ADSL Routers providing there is a page that lists the remote IP on its own. # Further modification may be made to this script however if you make any modifications please send # me a copy ( send any updates or changes to updateip@borg.co.nz ) # the script can be setup as a cron job and called via wget or lynx. Its up to you how # often you want it to refresh but I'm intending to have it refresh every minute. # This scipt is copywrite (C) of Andrew Hooper 2003 updateip@borg.co.nz. $stat_file = 'remote_ip'; # Name of the status file (apache must have write permissions in the directory) $log_file = 'dynamic_ip.log'; # log the history to this file $DSL_Username = 'admin'; # ADSL Router Username $DSL_Password = 'XXXXX'; # ADSL Router Password $DSL_Address = '[http://192.168.1.1/wanstatus.html';](http://192.168.1.1/wanstatus.html';) #URL on the router that displays the remote IP $IP_Update_URL[] = '[http://freedns.afraid.org/dynamic/update.php?QUERY_STRING';](http://freedns.afraid.org/dynamic/update.php?QUERY_STRING';) # URL to open for updating the IP $IP_Update_URL[] = '[http://freedns.afraid.org/dynamic/update.php?QUERY_STRING';](http://freedns.afraid.org/dynamic/update.php?QUERY_STRING';) # URL to open for updating the IP $IP_Update_URL[] = '[http://freedns.afraid.org/dynamic/update.php?QUERY_STRING';](http://freedns.afraid.org/dynamic/update.php?QUERY_STRING';) # URL to open for updating the IP $debug = 'ON'; #Debuging ON / OFF ################################################################## ## You should not need to edit beyond this point ## ################################################################## if(ereg('(http:\/\/)(.*)',$DSL_Address,$DSL_regs)){ if(!$DSL_Username && !$DSL_Password){ $DSL_url = $DSL_regs[1] . $DSL_regs[2]; # If there is no Username and Password }else{ $DSL_url = $DSL_regs[1] . $DSL_Username . ":" . $DSL_Password . "@" . $DSL_regs[2]; # if there is a Username and Password } $DSL_Status = implode('',file($DSL_url)); $DSL_Status = strip_tags($DSL_Status, ''); $ipok = 0; if(ereg('([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})',$DSL_Status,$IP_regs)){ for($i=1; $i < 5; $i++){ $ip_segment[$i] = intval($IP_regs[$i]); if($ip_segment[$i] <= 255) $ipok++; } $ip = implode(".", $ip_segment); } } $lastIP_Status = implode('',file($stat_file)); if(ereg('([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})',$lastIP_Status,$lastIP_regs)){ if($debug='ON'){echo "Last IP was : " . $lastIP_regs[0] . "\n\r";} $last_IP = $lastIP_regs[0]; } if($ip == $last_IP){ if($debug='ON'){echo "No change to IP : " . $ip ."\n\r";} }else{ # Create or Alter the status file. if($debug='ON'){echo "Changing IP from : " . $last_IP . " to : " . $ip . "\n\r";} $fname = $stat_file; $fp = fopen($fname,'w+'); $log_ip = $ip . " Date: " . date("F j, Y, g:i a") . "\n\r"; fwrite($fp,$log_ip); fclose($fp); $fname = $log_file; $fp = fopen($fname,'a'); while(list($key, $val) = each($IP_Update_URL)){ $dynamic_update = implode('',file($val)); # Create and or write to the log file. $log_ip = "Date: " . date("F j, Y, g:i a") . " - Response :" . $dynamic_update . "\n\r"; if($debug='ON'){echo $dynamic_update . "\n\r";} } fwrite($fp,$log_ip); fclose($fp); } ?>Mais bon rien ne s'affiche sur ma page .html par défaut et je n'y connais pas grand chose en php. J'essaye néanmoins d'exécuter le script phpupdate.php à la main avec la ligne de commande: php phpupdate.php et j'obtiens : Warning: file(remote_ip): failed to open stream: No such file or directory in /var/www/apache2-default/phpupdate.php on line 55 Warning: implode(): Bad arguments. in /var/www/apache2-default/phpupdate.php on line 55 No change to IP :