Prerequisites
- PHP 8.1+ with
ip-api-io/ipapi-phpinstalled - A free ip-api.io API key
Autonomous system with asn
Returns the ASN, owning organization, network range, and country for an IP — and whether it belongs to a datacenter.
<?php
use IpApiIo\Client;
$client = new Client(apiKey: getenv('IP_API_IO_KEY'));
$asn = $client->asn('8.8.8.8');
echo $asn['asn']; // 15169
echo $asn['organization']; // "Google LLC"
echo $asn['network']; // "8.8.8.0/24"
var_dump($asn['is_datacenter']); // true
echo $asn['country_code']; // "US" Domain registration with whois
WHOIS record for a domain: registrar, registration/expiry/update dates, name servers, status codes, and the raw WHOIS text.
$whois = $client->whois('example.com');
echo $whois['registrar']['name'];
echo $whois['registered_on']; // "1995-08-14"
echo $whois['expires_on'];
print_r($whois['name_servers']); // ["a.iana-servers.net", ...]
echo $whois['status'][0]['humanized']; DNS with reverseDns, forwardDns & mxRecords
Resolve a PTR record, resolve a hostname to addresses, or list a domain's mail servers.
$rdns = $client->reverseDns('8.8.8.8');
echo $rdns['hostname']; // "dns.google"
$fdns = $client->forwardDns('dns.google');
foreach ($fdns['addresses'] as $record) {
echo $record['type'], ' ', $record['address'], ' ', $record['ttl']; // "A" "8.8.8.8" 300
}
$mx = $client->mxRecords('example.com');
foreach ($mx['mx_records'] as $record) {
echo $record['priority'], ' ', $record['hostname'], ' ', $record['ttl'];
}