Skip to content
/ ip2asn Public

🤖IP address to autonomous system number (ASN)

License

Notifications You must be signed in to change notification settings

picatz/ip2asn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

🤖IP address to autonomous system number (ASN)

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published