Skip to content

Instantly share code, notes, and snippets.

@codenift
Created November 20, 2020 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codenift/a8bf37a5bb5faffba35c557f4fb5406f to your computer and use it in GitHub Desktop.
Save codenift/a8bf37a5bb5faffba35c557f4fb5406f to your computer and use it in GitHub Desktop.
<?php
$login = 'admin';
$password = 'your-password';
$mount = '/live';
$server = 'sndo.net:8000';
$url = "http://$server/admin/listclients?mount=$mount";
$opts = array('http' => array(
'method' => 'GET',
'header' => 'Authorization: Basic '.base64_encode("$login:$password")."\r\n"
));
$context = stream_context_create($opts);
$xml = @file_get_contents($url, false, $context);
if( !$xml ) {
echo "<p>Sorry, no mountpoint found.</p>\n";
exit();
}
$listeners = new SimpleXMLElement($xml);
$unknown = 'Unknown';
$bycity = array();
$bycountry = array();
foreach( $listeners->source->listener as $listener ) {
$l = array();
$l['ip'] = (string)$listener->IP;
$l['time'] = (string)$listener->Connected;
//Test: print_r($l)
//Output on test would be: Array ( [ip] => 64.xxx.xx.xxx [time] => 183 )
// Example using https://ipinfodb.com API
$location = $location->ip ($l['ip']);
// Values returned
$location['country'];
$location['country_code'];
$location['state'];
$location['city'];
$location['post_code'];
$location['latitude'];
$location['longitude'];
//then you can use this info for the map
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment