Skip to content

Instantly share code, notes, and snippets.

@lpellegr
Last active January 13, 2020 10:10
Show Gist options
  • Save lpellegr/4587d83215e8ceeaf74b811dd4308975 to your computer and use it in GitHub Desktop.
Save lpellegr/4587d83215e8ceeaf74b811dd4308975 to your computer and use it in GitHub Desktop.
Retrieve IP Info in PHP for a list of IP addresses using ipregistry.co
<?php
$curl = curl_init();
$payload = json_encode(array("66.165.2.7", "1.1.1.1", "8.8.4.4"));
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.ipregistry.co/?key=tryout",
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => array('Content-Type:application/json'),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_CUSTOMREQUEST => "POST",
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "An error occurred while retrieving IP info:" . $err;
} else {
$ipinfo = json_decode($response, true);
print_r($ipinfo['results']);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment