README
¶
ip2asn
Command line tool to map IP addresses to ASNs using IP-to-ASN mappings from https://iptoasn.com.
This tool also uses the IP2Location LITE database for optional IP geolocation.
Installation
Requires go 1.26.
go install codeberg.org/tomcz/ip2asn@latest
Usage
Usage: ip2asn [options] ip_address ...
Options:
-all
Resolve all IPs including restricted
-cache string
Cache directory location (default "$HOME/.cache/ip2asn")
-debug
Show debug logs
-json
Display results in JSON format
-offline
Offline mode: use only previously cached files
-token string
IP2Location LITE token [env: IP2LOCATION_TOKEN]
Examples
Default table output format:
$> ip2asn 8.8.8.8 1.1.1.1 9.9.9.9
┌─────────┬───────┬───────────────┬─────────┬─────────────┬───────────┐
│ IP │ ASN │ DESCRIPTION │ COUNTRY │ RANGE START │ RANGE END │
├─────────┼───────┼───────────────┼─────────┼─────────────┼───────────┤
│ 8.8.8.8 │ 15169 │ GOOGLE │ US │ 8.8.8.0 │ 8.8.8.255 │
│ 1.1.1.1 │ 13335 │ CLOUDFLARENET │ US │ 1.1.1.0 │ 1.1.1.255 │
│ 9.9.9.9 │ 19281 │ QUAD9-AS-1 │ US │ 9.9.9.0 │ 9.9.9.255 │
└─────────┴───────┴───────────────┴─────────┴─────────────┴───────────┘
Alternative JSON output format:
$> ip2asn -json 8.8.8.8 1.1.1.1 9.9.9.9
[
{
"ip": "8.8.8.8",
"match": {
"range_start": "8.8.8.0",
"range_end": "8.8.8.255",
"asn": 15169,
"country_code": "US",
"description": "GOOGLE"
}
},
{
"ip": "1.1.1.1",
"match": {
"range_start": "1.1.1.0",
"range_end": "1.1.1.255",
"asn": 13335,
"country_code": "US",
"description": "CLOUDFLARENET"
}
},
{
"ip": "9.9.9.9",
"match": {
"range_start": "9.9.9.0",
"range_end": "9.9.9.255",
"asn": 19281,
"country_code": "US",
"description": "QUAD9-AS-1"
}
}
]
Geolocation
This tool will use the https://lite.ip2location.com database for geolocation when provided with your download token as either a IP2LOCATION_TOKEN environment variable or a -token command line flag.
Default table output format:
$> export IP2LOCATION_TOKEN='your download token'
$> ip2asn 8.8.8.8 1.1.1.1 9.9.9.9
┌─────────┬───────┬───────────────┬─────────┬──────────────────────────┬────────────┬───────────────┐
│ IP │ ASN │ DESCRIPTION │ COUNTRY │ IP COUNTRY │ IP REGION │ IP CITY │
├─────────┼───────┼───────────────┼─────────┼──────────────────────────┼────────────┼───────────────┤
│ 8.8.8.8 │ 15169 │ GOOGLE │ US │ United States of America │ California │ Mountain View │
│ 1.1.1.1 │ 13335 │ CLOUDFLARENET │ US │ Australia │ Queensland │ Brisbane │
│ 9.9.9.9 │ 19281 │ QUAD9-AS-1 │ US │ United States of America │ California │ Berkeley │
└─────────┴───────┴───────────────┴─────────┴──────────────────────────┴────────────┴───────────────┘
Alternative JSON output format:
$> export IP2LOCATION_TOKEN='your download token'
$> ip2asn -json 8.8.8.8 1.1.1.1 9.9.9.9
[
{
"ip": "8.8.8.8",
"match": {
"range_start": "8.8.8.0",
"range_end": "8.8.8.255",
"asn": 15169,
"country_code": "US",
"description": "GOOGLE"
},
"location": {
"network": "::ffff:8.8.8.0/120",
"country_code": "US",
"country": "United States of America",
"region": "California",
"city": "Mountain View"
}
},
{
"ip": "1.1.1.1",
"match": {
"range_start": "1.1.1.0",
"range_end": "1.1.1.255",
"asn": 13335,
"country_code": "US",
"description": "CLOUDFLARENET"
},
"location": {
"network": "::ffff:1.1.1.0/120",
"country_code": "AU",
"country": "Australia",
"region": "Queensland",
"city": "Brisbane"
}
},
{
"ip": "9.9.9.9",
"match": {
"range_start": "9.9.9.0",
"range_end": "9.9.9.255",
"asn": 19281,
"country_code": "US",
"description": "QUAD9-AS-1"
},
"location": {
"network": "::ffff:9.9.9.0/120",
"country_code": "US",
"country": "United States of America",
"region": "California",
"city": "Berkeley"
}
}
]
Documentation
¶
There is no documentation for this package.
Click to show internal directories.
Click to hide internal directories.