Skip to content

Instantly share code, notes, and snippets.

@6footgeek
Created August 23, 2017 09:54
Show Gist options
  • Save 6footgeek/59a8724c06328626c83d03efbb9f3341 to your computer and use it in GitHub Desktop.
Save 6footgeek/59a8724c06328626c83d03efbb9f3341 to your computer and use it in GitHub Desktop.
IP to ASN lookup PHP
private function getAsnFromIP($ip)
{
$query = 'whois -h whois.cymru.com " -f ' . (string) $ip . '"';
$whoisResult = shell_exec($query);
$asnArray = explode('|', $whoisResult);
$cleanAsn = array_map('trim', $asnArray);
return $cleanAsn;
}
@x011
Copy link

x011 commented Mar 21, 2023

@victorelec14 You'll need to install PECL geoip >= 1.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment