Skip to content

Instantly share code, notes, and snippets.

@markallenpark
Created September 25, 2023 20:08
Show Gist options
  • Save markallenpark/b98ebf01a1153e131d3dce6b00cb35fc to your computer and use it in GitHub Desktop.
Save markallenpark/b98ebf01a1153e131d3dce6b00cb35fc to your computer and use it in GitHub Desktop.
Simple utility to display external IP for updating dyndns
<?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