Created
September 25, 2023 20:08
-
-
Save markallenpark/b98ebf01a1153e131d3dce6b00cb35fc to your computer and use it in GitHub Desktop.
Simple utility to display external IP for updating dyndns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$client_ip = $_SERVER['REMOTE_ADDR']; | |
$ip_version = (filter_var($client_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) ? | |
'4' : | |
'6'; | |
$tz = new DateTimeZone('UTC'); | |
$datetime = new DateTime(); | |
$datetime->setTimezone($tz); | |
$data = [ | |
'time' => $datetime->format('c'), | |
'ip' => [ | |
'version' => $ip_version, | |
'address' => $client_ip | |
] | |
]; | |
header('Content-Type: application/json; charset=utf-8'); | |
echo json_encode($data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment