Project

ip2asn

0.0
No release in over 3 years
Low commit activity in last 3 years
IP address to ASN library using iptoasn.com
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.16
~> 10.0
~> 3.0

Runtime

~> 1.7.3
 Project Readme

Ip2asn

IP address to autonomous system number (ASN)

This library uses the free IP-to-ASN service provided by iptoasn.com

Installation

$ gem install ip2asn

Usage

require 'ip2asn'

IP2ASN.check("8.8.8.8")
# => {
#      "announced"=>true,
#      "as_country_code"=>"US",
#      "as_description"=>"GOOGLE - Google LLC",
#      "as_number"=>15169,
#      "first_ip"=>"8.8.8.0",
#      "ip"=>"8.8.8.8",
#      "last_ip"=>"8.8.8.255"
# }

Get raw JSON response:

raw_json = IP2ASN.check("8.8.8.8" json: true)

Download the IPv4 to ASN map and save the file as ipv4.tsv:

IP2ASN.download_ipv4_to_asn_map(file: "ipv4.tsv")

Download the IPv4 to ASN map and save the file as ipv4_u32.tsv with IPv4 addresses as 32-bit unsigned integers:

IP2ASN.download_ipv4_to_asn_map(file: "ipv4_u32.tsv", u32: true)

Read content of the IPv4 map, line by line (this time not saving to a file):

IP2ASN.download_ipv4_to_asn_map do |line|
  # do something with line from file
  puts line
end

Download the IPv6 to ASN map and save the file as ipv6.tsv:

IP2ASN.download_ipv6_to_asn_map(file: "ipv6.tsv")

Download the combined IPv4+IPv6 to ASN map and save the file as ip.tsv:

IP2ASN.download_ip_to_asn_map(file: "ip.tsv")

License

The gem is available as open source under the terms of the MIT License.