PHP Classes
elePHPant
Icontem

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

Details

ip2asn

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

Cache Purging

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

Dependencies

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

$ apt install whois

Usage

use peterkahl\ip2asn\ip2asn;

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

var_dump($temp);

/*
array(7) {
  ["as_number"]=>
  string(5) "15169"
  ["as_prefix"]=>
  string(10) "8.8.8.0/24"
  ["as_prefix_bin"]=>
  string(24) "000010000000100000001000"
  ["as_country_code"]=>
  string(2) "US"
  ["as_isp"]=>
  string(24) "GOOGLE - Google Inc., US"
  ["as_nic"]=>
  string(4) "ARIN"
  ["as_alloc"]=>
  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);

var_dump($temp);
  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Accessible without login Plain text file asn-cache-purge.sh 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 README.md 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  
 100%
Total:67
This week:0
All time:8,931
This week:609Up