PHP-DynIP

dynip.php

<?php

$logging = 'yes';

$users = array('USER1', 'USER2', 'USER3');
$login_passwort = 'PASSWORT';

date_default_timezone_set('Europe/Berlin');
setlocale(LC_TIME, 'de_DE');

$log_dir = 'logs';
$dynip_dir = 'dynips';
$result = 'good';

$passwort = $_GET['pass'];
$user = $_GET['user'];
$domain = $_SERVER['SERVER_NAME'];

if ( isset($_GET['myip']) ) {
	$request_ip = False;
	$dynip = $_GET['myip'];
	$state = 'set ip to '.$dynip;
} else {
	$request_ip = True;
	$state = 'requested ip';	
}

if ( ($passwort == $login_passwort) && (in_array($user, $users)) ) {
	$ip_file = "{$dynip_dir}/{$user}.txt";
	if ( $request_ip ) {
		if ( file_exists($ip_file) ) {
			$file = fopen("$ip_file", "r");
			$ip = fread($file,filesize($ip_file));
			fclose($file);
			echo "{$ip}";
		} else {
			$result = 'bad';
?>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /dyndns/dynip.php was not found on this server.</p>
</body></html>
<?php	}
	} else {
		if ( !file_exists($dynip_dir) ) {
			mkdir($dynip_dir, 0777, true);
		}
		if ( !file_exists($ip_file) ) {
			$file = fopen("$ip_file", "w+");
			fwrite($file, "127.0.0.1");
			fclose($file);
		}
		if ( $dynip !== "" ); {
			$file = fopen("$ip_file", "w");
			fwrite($file, $dynip);
			fclose($file);
			echo "good";
		}
	}
} else {
	$user = 'unknown user';
	$result = 'fail';
?>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /dyndns/dynip.php was not found on this server.</p>
</body></html>
<?php
}



if ( $logging == 'yes' ) {
	if ( !file_exists($log_dir) ) {
		mkdir($log_dir, 0777, true);
	}
	$log_file = "{$log_dir}/".date('Y-m').".txt";
	$date = date("Y-m-d H:i:s",time());
	$append_to_log = "{$date} - {$user} {$state} => {$result}\n";
	$file = fopen("$log_file", "a");
	fwrite($file, $append_to_log);
	fclose($file);
}

?>

  • $users = array(<Benutzer hier eintragen>);
  • $login_passwort = '<Passwort hier eintragen>';

Abfrage der IP
curl "https://your.domain/dynip.php?pass=PASSWORT&user=USER1"

Setzen der IP
curl "https://your.domain/dynip.php?pass=PASSWORT&user=USER1&myip=9.9.9.9"

Einstellungen in der Fritzbox

  • DynDNS-Anbieter: Benutzerdefiniert
  • Update-URL: https://your.domain/dynip.php?user=<username>&pass=<pass>&myip=<ipaddr>
  • Domainname: fritz.box
  • Benutzername: USER1
  • Kennwort: PASSWORT