PHP Classes

PHP IP to ASN Mapping: Map IPv4 or IPv6 address to ASN

Recommend this page to a friend!
  Info   View files Documentation   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-06-18 (4 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 67 All time: 8,931 This week: 609Up
Version License PHP version Categories
ip2asn 1.0Custom (specified...5Networking, PHP 5
Description Author

This class can map IPv4 or IPv6 address to ASN.

It can take a given IP address either in IPv4 or IPv6 format and get the autonomous system number for that IP address querying the cymru whois service.

The results are cached to avoid overhead of accessing the whois cymru service for the same IP ASN query.

Innovation Award
PHP Programming Innovation award nominee
July 2017
Number 6
An autonomous system is a part of network that is connected to other networks according to routing definitions.

An autonomous system number (ASN) is a number assigned to each network. A computer with an IP address belongs to a given network with its own ASN.

This class can determine what is the ASN of a given IPv4 or IPv6 address by calling the cymru whoi service that is now very huge.

Manuel Lemos
  Performance   Level  
Name: Peter Kahl <contact>
Classes: 32 packages by
Country: Hong Kong Hong Kong
Age: ???
All time rank: 6734 in Hong Kong Hong Kong
Week rank: 14 Up1 in Hong Kong Hong Kong Up
Innovation award
Innovation award
Nominee: 19x



IP address intelligence. Maps IP address to ASN. ASN to prefix.

Cache Purging

Essential component of this library is the shell script, which is to be installed into location of your choice and shall be executed hourly using crontab. (Edit parameters as needed.)


You will need the whois package, which you can install with this or similar command:

$ apt install whois


use peterkahl\ip2asn\ip2asn;

$asnObj = new ip2asn;
$asnObj->cacheDir = '/srv/cache';
$temp = $asnObj->getAsn(''); # Accepts both IPv4 and IPv6


array(7) {
  string(5) "15169"
  string(10) ""
  string(24) "000010000000100000001000"
  string(2) "US"
  string(24) "GOOGLE - Google Inc., US"
  string(4) "ARIN"
  string(0) "NA"

use peterkahl\ip2asn\ip2asn;

$asnObj = new ip2asn;
$asnObj->cacheDir = '/srv/cache';

# This will get us an array of all prefixes for AS 94, 95, 96.
$temp = $asnObj->ArrayAsn2prefix(array(94, 95, 96);

  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Accessible without login Plain text file Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file ip2asn.php Class Class source

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:8,931
This week:609Up