Skip to content

Instantly share code, notes, and snippets.

@vavrecan
Created February 7, 2025 19:30
Show Gist options
  • Save vavrecan/a31ace061e270a50060dc3bdfa3117e8 to your computer and use it in GitHub Desktop.
Save vavrecan/a31ace061e270a50060dc3bdfa3117e8 to your computer and use it in GitHub Desktop.
<?php
// service -> dyndnscustom
// host ->
$username = "";
$password = "";
$host = "";
if (empty($_SERVER["PHP_AUTH_USER"]) || $_SERVER["PHP_AUTH_USER"] != $username) {
die("badauth");
}
if (empty($_SERVER["PHP_AUTH_PW"]) || $_SERVER["PHP_AUTH_PW"] != $password) {
die("badauth");
}
$public_ip = $_SERVER['REMOTE_ADDR'];
$current_ip = file_get_contents("ip.txt");
if ($current_ip == $public_ip) {
die("nochg");
}
$url = "https://api.cloudflare.com/client/v4/zones/..../dns_records/....";
$headers = [
"Content-Type: application/json",
"Authorization: Bearer ....",
];
$data = [
"comment" => "",
"content" => $public_ip,
"name" => $host,
"proxied" => false,
"ttl" => 60,
"type" => "A"
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
curl_close($ch);
file_put_contents("ip.txt", $public_ip);
die("ok " . $public_ip);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment