Install asnmap
mainasnmap requires Go 1.21 or later. You can install it using go install or by downloading pre-compiled binaries from the GitHub releases page.
go install github.com/projectdiscovery/asnmap/cmd/asnmap@latestrepository·main·Indexed 22 days ago
https://github.com/projectdiscovery/asnmapA Go-based CLI and library used to map network information—including ASNs, Organizations, DNS, or IP addresses—to their corresponding CIDR ranges. Designed for reconnaissance and attack surface expansion, it supports JSON and CSV output and integrates with other ProjectDiscovery tools like tlsx, dnsx, naabu, and nuclei. Requires Go 1.21 or later and a ProjectDiscovery Cloud Platform API token for authentication.
asnmap requires Go 1.21 or later. You can install it using go install or by downloading pre-compiled binaries from the GitHub releases page.
go install github.com/projectdiscovery/asnmap/cmd/asnmap@latestasnmap can take various input types to resolve CIDR ranges. It supports single values, multiple comma-separated values, or reading from a file. It also supports STDIN for piping data.
Supported input types:
AS14421example.com93.184.216.34GOOGLE# Using specific flags
asnmap -a AS45596 -silent
asnmap -i 100.19.12.21 -silent
asnmap -d hackerone.com -silent
asnmap -org GOOGLE -silent
# Using STDIN
echo GOOGLE | ./asnmap -silentSince asnmap supports STDIN and provides CIDR ranges, its output can be piped directly into other ProjectDiscovery tools to expand attack surfaces.
Common patterns include:
tlsx for TLS inspection.dnsx for DNS resolution.naabu for port scanning.naabu results into httpx or nuclei.echo AS54115 | asnmap | naabu -p 443 | httpx | nuclei -id tech-detectThe ASNMap CLI requires an API Token from the ProjectDiscovery Cloud Platform. You can authenticate using one of two methods:
PDCP_API_KEY variable.-auth flag to enter your key manually.# Method 1: Environment Variable
export PDCP_API_KEY=*************
# Method 2: Interactive
asnmap -authThe asnmap client requires an API key to interact with the ProjectDiscovery cloud API.
Authentication Methods:
PDCP_API_KEY environment variable. This is the recommended method for programmatic use.pdcp.PDCPCredHandler during initialization.Errors:
ErrUnAuthorized (which corresponds to a 401 Unauthorized HTTP status).# Set the API key in your environment
export PDCP_API_KEY="your_api_key_here"Use the -csv flag to output data in a pipe-delimited CSV format. The fields included are timestamp|input|as_number|as_name|as_country|as_range.
echo hackerone.com | ./asnmap -csv -silentFor automation and post-processing, use the -json flag. This returns a structured JSON object containing the timestamp, input, ASN number, ASN name, country, and an array of CIDR ranges.
echo hackerone.com | ./asnmap -json -silent | jqThe following flags are available for the asnmap command line tool:
INPUT:
-a, -asn string[] target asn to lookup, example: -a AS5650
-i, -ip string[] target ip to lookup, example: -i 100.19.12.21, -i 2a10:ad40::
-d, -domain string[] target domain to lookup, example: -d google.com, -d facebook.com
-org string[] target organization to lookup, example: -org GOOGLE
-f, -file string[] targets to lookup from file
CONFIGURATIONS:
-config string path to the asnmap configuration file
-r, -resolvers string[] list of resolvers to use
UPDATE:
-up, -update update asnmap to latest version
-duc, -disable-update-check disable automatic asnmap update check
OUTPUT:
-o, -output string file to write output to
-j, -json display json format output
-c, -csv display csv format output
-v6 display ipv6 cidr ranges in cli output
-v, -verbose display verbose output
-silent display silent output
-version show version of the projectTo use asnmap as a library, initialize a new Client using NewClient(). The client automatically determines the base server URL from the SERVER_URL environment variable or defaults to https://asn.projectdiscovery.io/. The client is configured to ignore expired SSL certificates by default.
Note: You must provide a valid API key via the PDCP_API_KEY environment variable or through the ProjectDiscovery credential handler for requests to succeed.
package main
import (
"fmt"
"github.com/projectdiscovery/asnmap"
)
func main() {
client, err := asnmap.NewClient()
if err != nil {
panic(err)
}
fmt.Printf("Client initialized: %+v\n", client)
}The GetData method is the primary way to perform ASN, IP, or Organization lookups. It automatically identifies the input type (ASN, ASNID, IP, or Org) and constructs the appropriate API request.
Input Types Supported:
AS1234 (the method will strip the as prefix internally).1234.8.8.8.8.Google.Parameters:
input string: The value to query.medatadas ...string: Optional metadata parameters (variadic).Returns:
[]*Response: A slice of response objects containing the lookup results.error: An error if the input type is unknown, the request fails, or the API returns an error (e.g., ErrUnAuthorized).// Example: Lookup an IP
results, err := client.GetData("8.8.8.8")
if err != nil {
// handle error
}
// Example: Lookup an ASN
results, err := client.GetData("AS15169")You can route asnmap client requests through a proxy using the SetProxy method. This method supports both direct proxy strings and proxy lists (which can include file paths).
Supported Proxy Schemes:
http / httpssocks5Usage Patterns:
If no valid proxy can be established, SetProxy returns an error.
// Using a single proxy string
_, err := client.SetProxy([]string{"http://proxy.example.com:8080"})
// Using a file containing a list of proxies
_, err := client.SetProxy([]string{"/path/to/proxies.txt"})If you need the Input field in the returned Response objects to match a specific string rather than the automatically identified input, use GetDataWithCustomInput. This is useful when you want to preserve the exact formatting of your original query in the results.
// The 'inputToUseInResponse' will be assigned to the 'Input' field of every result
results, err := client.GetDataWithCustomInput("AS15169", "google_asn")