### Install asnmap CLI and Add as Go Library Source: https://context7.com/projectdiscovery/asnmap/llms.txt Install the asnmap CLI tool using 'go install' or add it as a dependency to your Go project. ```bash # Install CLI tool go install github.com/projectdiscovery/asnmap/cmd/asnmap@latest ``` ```bash # Add as a Go library dependency go get github.com/projectdiscovery/asnmap ``` -------------------------------- ### Install ASNMap CLI Source: https://github.com/projectdiscovery/asnmap/blob/main/README.md Install the ASNMap CLI tool using Go. Requires Go 1.21 or later. ```console go install github.com/projectdiscovery/asnmap/cmd/asnmap@latest ``` -------------------------------- ### Chaining ASNMap with Other Tools Source: https://context7.com/projectdiscovery/asnmap/llms.txt Demonstrates piping ASNMap's output to other ProjectDiscovery tools for various network tasks. Ensure tools like naabu, httpx, nuclei, dnsx, and tlsx are installed and in your PATH. ```bash # Scan port 443 across all GOOGLE IP ranges echo AS54115 | asnmap | naabu -p 443 ``` ```bash # Full recon pipeline: ASN → IPs → open ports → HTTP probing → vulnerability scan echo AS54115 | asnmap | naabu -p 443 | httpx | nuclei -id tech-detect ``` ```bash # PTR record enumeration on all IPs in an ASN echo AS54115 | asnmap | dnsx -ptr ``` ```bash # TLS certificate enumeration echo AS54115 | asnmap | tlsx ``` -------------------------------- ### Pipe Input to ASNMap Source: https://github.com/projectdiscovery/asnmap/blob/main/README.md Use standard input to pipe data to ASNMap for processing. This example pipes 'GOOGLE' to the tool with silent output. ```console echo GOOGLE | ./asnmap -silent ``` -------------------------------- ### Run ASNMap with Different Input Types Source: https://github.com/projectdiscovery/asnmap/blob/main/README.md Examples of running ASNMap with various input types: ASN, IP address, domain name, and organization name. The '-silent' flag is used for concise output. ```console asnmap -a AS45596 -silent ``` ```console asnmap -i 100.19.12.21 -silent ``` ```console asnmap -d hackerone.com -silent ``` ```console asnmap -org GOOGLE -silent ``` -------------------------------- ### Create ASNMap API Client Source: https://context7.com/projectdiscovery/asnmap/llms.txt Initializes a new ASNMap HTTP client. It automatically reads the PDCP_API_KEY from the environment or stored credentials. ```go package main import ( "log" asnmap "github.com/projectdiscovery/asnmap/libs" ) func main() { client, err := asnmap.NewClient() if err != nil { log.Fatalf("failed to create client: %v", err) } _ = client } ``` -------------------------------- ### Fetch ASN Data with GetData Shortcut Source: https://context7.com/projectdiscovery/asnmap/llms.txt A convenience wrapper that uses the package-level DefaultClient singleton for simple use cases, avoiding manual client instantiation. Requires PDCP_API_KEY to be set in the environment. ```go package main import ( "log" asnmap "github.com/projectdiscovery/asnmap/libs" ) func main() { responses, err := asnmap.GetData("AS15169") if err != nil { log.Fatal(err) } for _, r := range responses { log.Printf("ASN: %d | Org: %s | Country: %s", r.ASN, r.Org, r.Country) } } ``` -------------------------------- ### Initialize and Run Asnmap Programmatically Source: https://context7.com/projectdiscovery/asnmap/llms.txt Use `runner.New` to create a new runner instance with custom options, including target ASNs, JSON output, and an optional result callback. The `runner.Run` method executes the scan. Ensure to close the runner using `defer r.Close()`. ```go package main import ( "log" "os" "github.com/projectdiscovery/asnmap/runner" asnmap "github.com/projectdiscovery/asnmap/libs" ) func main() { options := &runner.Options{ Asn: []string{"AS13335"}, DisplayInJSON: true, Output: os.Stdout, // OnResult callback fires for each batch of raw responses OnResult: func(responses []*asnmap.Response) { for _, r := range responses { log.Printf("[callback] ASN: %d Org: %s", r.ASN, r.Org) } }, } r, err := runner.New(options) if err != nil { log.Fatal(err) } defer r.Close() if err := r.Run(); err != nil { log.Fatal(err) } // Stdout receives JSON lines: // {"timestamp":"...","input":"AS13335","as_number":"AS13335","as_name":"CLOUDFLARENET","as_country":"US","as_range":["104.16.0.0/14",...]} } ``` -------------------------------- ### Configure PDCP API Key via Environment Variable Source: https://github.com/projectdiscovery/asnmap/blob/main/README.md Set the ProjectDiscovery Cloud Platform API key using an environment variable for authentication. ```console export PDCP_API_KEY=************* ``` -------------------------------- ### NewClient() Source: https://context7.com/projectdiscovery/asnmap/llms.txt Creates a new ASNMap HTTP client. It automatically reads the PDCP_API_KEY from the environment or stored credentials. ```APIDOC ## NewClient() ### Description Creates a new asnmap HTTP client pointed at the PDCP ASN API. Reads `PDCP_API_KEY` from the environment or stored credentials automatically. ### Usage ```go package main import ( "log" asnmap "github.com/projectdiscovery/asnmap/libs" ) func main() { client, err := asnmap.NewClient() if err != nil { log.Fatalf("failed to create client: %v", err) } _ = client } ``` ``` -------------------------------- ### Display ASNMap Help Source: https://github.com/projectdiscovery/asnmap/blob/main/README.md Display the help message for the ASNMap CLI tool to show all available flags and options. ```console asnmap -h ``` -------------------------------- ### runner.New and runner.Run Source: https://context7.com/projectdiscovery/asnmap/llms.txt Initializes a new ASNMap runner with specified options and then executes the scan. The `OnResult` callback is invoked for each batch of responses. ```APIDOC ## `runner.New(options)` / `runner.Run()` — Programmatic runner The `runner` package provides a higher-level entry point that handles all input normalization, deduplication (via hybrid on-disk map), domain resolution, and formatted output. Suitable for embedding asnmap behavior in larger Go programs. ```go package main import ( "log" "os" "github.com/projectdiscovery/asnmap/runner" asnmap "github.com/projectdiscovery/asnmap/libs" ) func main() { options := &runner.Options{ Asn: []string{"AS13335"}, DisplayInJSON: true, Output: os.Stdout, // OnResult callback fires for each batch of raw responses OnResult: func(responses []*asnmap.Response) { for _, r := range responses { log.Printf("[callback] ASN: %d Org: %s", r.ASN, r.Org) } }, } r, err := runner.New(options) if err != nil { log.Fatal(err) } defer r.Close() if err := r.Run(); err != nil { log.Fatal(err) } // Stdout receives JSON lines: // {"timestamp":"...","input":"AS13335","as_number":"AS13335","as_name":"CLOUDFLARENET","as_country":"US","as_range":["104.16.0.0/14",...]}} } ``` ``` -------------------------------- ### Integration with other PD Projects Source: https://github.com/projectdiscovery/asnmap/blob/main/README.md ASNMap's output can be piped directly into other ProjectDiscovery tools that accept stdin as input, enabling complex workflows. ```console echo AS54115 | asnmap | tlsx ``` ```console echo AS54115 | asnmap | dnsx -ptr ``` ```console echo AS54115 | asnmap | naabu -p 443 ``` ```console echo AS54115 | asnmap | naabu -p 443 | httpx ``` ```console echo AS54115 | asnmap | naabu -p 443 | httpx | nuclei -id tech-detect ``` -------------------------------- ### GetData Source: https://context7.com/projectdiscovery/asnmap/llms.txt A convenience wrapper that uses the package-level DefaultClient singleton, avoiding the need to instantiate a client manually for simple use cases. ```APIDOC ## GetData(input string) ### Description A convenience wrapper that uses the package-level `DefaultClient` singleton, avoiding the need to instantiate a client manually for simple use cases. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **responses** ([]*Response) - A slice of Response structs containing ASN information. ### Response Example None ``` -------------------------------- ### Set PDCP API Key via Environment Variable Source: https://context7.com/projectdiscovery/asnmap/llms.txt Set your ProjectDiscovery Cloud Platform API key as an environment variable to authenticate asnmap. ```bash # Option 1: environment variable export PDCP_API_KEY=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ``` -------------------------------- ### GetDataWithCustomInput(inputToQuery string, inputToUseInResponse string) Source: https://context7.com/projectdiscovery/asnmap/llms.txt Queries the API using one input but labels results with another. Useful for preserving domain names when querying by IP. ```APIDOC ## GetDataWithCustomInput(inputToQuery string, inputToUseInResponse string) ### Description Queries the API using `inputToQuery` but labels all results with `inputToUseInResponse`. Useful when you have resolved a domain to an IP and want the domain name preserved in output. ### Usage ```go package main import ( "log" asnmap "github.com/projectdiscovery/asnmap/libs" ) func main() { client, err := asnmap.NewClient() if err != nil { log.Fatal(err) } // Query by resolved IP, but label results with the original domain responses, err := client.GetDataWithCustomInput("104.21.3.157", "hackerone.com") if err != nil { log.Fatal(err) } for _, r := range responses { log.Printf("Input: %s, ASN: %d, Org: %s", r.Input, r.ASN, r.Org) } } ``` ### Example Output ``` Input: hackerone.com, ASN: 13335, Org: CLOUDFLARENET ``` ``` -------------------------------- ### Authenticate ASNMap CLI with API Key Source: https://github.com/projectdiscovery/asnmap/blob/main/README.md Interactively authenticate the ASNMap CLI tool by providing the PDCP API Key when prompted. This method is an alternative to using environment variables. ```console asnmap -auth ``` -------------------------------- ### Configure Proxy Routing with Client.SetProxy Source: https://context7.com/projectdiscovery/asnmap/llms.txt Configures the HTTP client to route requests through the first reachable proxy from a provided list. Supports HTTP, HTTPS, and SOCKS5 schemes, and can accept a file path with proxy URLs. ```go package main import ( "log" asnmap "github.com/projectdiscovery/asnmap/libs" ) func main() { client, err := asnmap.NewClient() if err != nil { log.Fatal(err) } proxyURL, err := client.SetProxy([]string{ "http://proxy1.example.com:8080", "socks5://proxy2.example.com:1080", }) if err != nil { log.Fatalf("no reachable proxy: %v", err) } log.Printf("Using proxy: %s", proxyURL.String()) responses, err := client.GetData("AS13335") if err != nil { log.Fatal(err) } log.Printf("Got %d responses", len(responses)) } ``` -------------------------------- ### File Input for asnmap Source: https://context7.com/projectdiscovery/asnmap/llms.txt Provide multiple targets from a file using the '-f' flag. The file can contain a mix of ASNs, IPs, domains, and organization names. ```bash # targets.txt contains: AS14421, 93.184.216.34, google.com, CLOUDFLARE asnmap -f targets.txt -silent ``` -------------------------------- ### Domain to CIDR Lookup Source: https://context7.com/projectdiscovery/asnmap/llms.txt Map a domain name to its corresponding ASN CIDR ranges by first resolving the domain to its IP addresses. ```bash asnmap -d hackerone.com -silent # Output: # 104.16.0.0/14 # 104.20.0.0/16 # 104.21.0.0/17 ``` -------------------------------- ### Client.SetProxy Source: https://context7.com/projectdiscovery/asnmap/llms.txt Configures the HTTP client to route requests through the first reachable proxy from the provided list. Supports HTTP, HTTPS, and SOCKS5 schemes. Can also accept a file path containing one proxy URL per line. ```APIDOC ## Client.SetProxy(proxyList []string) ### Description Configures the HTTP client to route requests through the first reachable proxy from the provided list. Supports HTTP, HTTPS, and SOCKS5 schemes. Can also accept a file path containing one proxy URL per line. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **proxyURL** (*url.URL) - The URL of the first reachable proxy that was successfully configured. ### Response Example None ``` -------------------------------- ### Default Run Source: https://github.com/projectdiscovery/asnmap/blob/main/README.md By default, asnmap returns the CIDR range for the given input. Ensure you use the tool responsibly. ```console echo GOOGLE | ./asnmap ___ _____ __ / _ | / __/ |/ /_ _ ___ ____ / __ |_\]/ / ' \/ _ / _ \ /_/ |_/___/_/|_/_/_/_/\_,_/ .__/ /_/ v0.0.1 projectdiscovery.io Use with caution. You are responsible for your actions Developers assume no liability and are not responsible for any misuse or damage. 8.8.4.0/24 8.8.8.0/24 8.35.200.0/21 34.3.3.0/24 34.4.4.0/24 34.96.0.0/20 34.96.32.0/19 34.96.64.0/18 34.98.64.0/18 34.98.136.0/21 34.98.144.0/21 ``` -------------------------------- ### Interactive ASN Authentication Source: https://context7.com/projectdiscovery/asnmap/llms.txt Authenticate interactively with asnmap by providing your PDCP API Key. This method stores credentials on disk. ```bash # Option 2: interactive authentication (stores credentials to disk) asnmap -auth # [INF] Get your free api key by signing up at https://cloud.projectdiscovery.io # [*] Enter PDCP API Key (exit to abort): xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx # [INF] Successfully logged in as (@user) ``` -------------------------------- ### Write Output to File Source: https://context7.com/projectdiscovery/asnmap/llms.txt Redirect the results of an asnmap query to a specified file instead of, or in addition to, standard output. ```bash asnmap -org GOOGLE -silent -o google-ranges.txt ``` -------------------------------- ### Resolve Domain to IP Addresses Source: https://context7.com/projectdiscovery/asnmap/llms.txt Performs DNS resolution for domain names to IPv4 (A) and IPv6 (AAAA) records. Uses Google's resolvers by default, but custom resolvers can be provided. ```go package main import ( "log" asnmap "github.com/projectdiscovery/asnmap/libs" ) func main() { // Default resolvers ips, err := asnmap.ResolveDomain("hackerone.com") if err != nil { log.Fatal(err) } log.Printf("Resolved IPs: %v", ips) // Output: Resolved IPs: [104.16.99.52 104.16.100.52 2606:4700::6810:6334 ...] // Custom resolvers ips2, err := asnmap.ResolveDomain("example.com", "1.1.1.1:53", "9.9.9.9:53") if err != nil { log.Fatal(err) } log.Printf("Resolved IPs (custom resolvers): %v", ips2) } ``` -------------------------------- ### Proxy Support for API Requests Source: https://context7.com/projectdiscovery/asnmap/llms.txt Route asnmap API requests through an HTTP, HTTPS, or SOCKS5 proxy using the '-p' flag. A file containing proxy addresses can also be supplied. ```bash asnmap -d example.com -silent -p http://127.0.0.1:8080 ``` ```bash asnmap -d example.com -silent -p socks5://127.0.0.1:1080 ``` ```bash # Supply a file of proxies (first reachable proxy is used) asnmap -d example.com -silent -p proxies.txt ``` -------------------------------- ### Convert Responses to Enriched Results with MapToResults Source: https://context7.com/projectdiscovery/asnmap/llms.txt Transforms raw *Response objects into *Result structs for JSON and CSV output. Ensures human-readable timestamps, AS-prefixed ASN strings, and full CIDR range lists. ```go package main import ( "encoding/json" "log" asnmap "github.com/projectdiscovery/asnmap/libs" ) func main() { client, err := asnmap.NewClient() if err != nil { log.Fatal(err) } responses, err := client.GetData("AS13335") if err != nil { log.Fatal(err) } results, err := asnmap.MapToResults(responses) if err != nil { log.Fatal(err) } for _, result := range results { out, _ := json.MarshalIndent(result, "", " ") log.Println(string(out)) } } ``` -------------------------------- ### GetData(input string) Source: https://context7.com/projectdiscovery/asnmap/llms.txt Queries ASN data for any input type (ASN, IP, or organization name). Returns raw IP pairs and ASN metadata. ```APIDOC ## GetData(input string) ### Description The primary query method. Automatically detects whether the input is an ASN, IP, or organization name and builds the correct API request. Returns a slice of `*Response` containing raw first/last IP pairs and ASN metadata. ### Usage ```go package main import ( "encoding/json" "log" asnmap "github.com/projectdiscovery/asnmap/libs" ) func main() { client, err := asnmap.NewClient() if err != nil { log.Fatal(err) } // Works with ASN number, IP address, or organization name for _, input := range []string{"14421", "210.10.122.10", "pplinknet"} { responses, err := client.GetData(input) if err != nil { log.Printf("error querying %s: %v", input, err) continue } out, _ := json.MarshalIndent(responses, "", " ") log.Printf("Results for %s:\n%s\n", input, string(out)) } } ``` ### Example Output ```json [ { "first_ip": "103.100.209.0", "last_ip": "103.100.209.255", "asn": 14421, "country": "PK", "org": "PPLINKNET" } ] ``` ``` -------------------------------- ### CSV Output Format Source: https://context7.com/projectdiscovery/asnmap/llms.txt Produce pipe-delimited CSV output with fields similar to JSON, suitable for spreadsheet import or further data manipulation. ```bash echo hackerone.com | asnmap -csv -silent # Output: # timestamp|input|as_number|as_name|as_country|as_range # 2022-09-19 12:15:04.906664007 +0530 IST|hackerone.com|AS13335|CLOUDFLARENET|US|104.16.0.0/14,104.20.0.0/16,104.21.0.0/17 ``` -------------------------------- ### Query ASN Data by Input Type Source: https://context7.com/projectdiscovery/asnmap/llms.txt Queries ASN data using the primary method. Automatically detects input type (ASN, IP, or organization name) and returns raw IP pairs and ASN metadata. Handles errors for individual queries. ```go package main import ( "encoding/json" "log" asnmap "github.com/projectdiscovery/asnmap/libs" ) func main() { client, err := asnmap.NewClient() if err != nil { log.Fatal(err) } // Works with ASN number, IP address, or organization name for _, input := range []string{"14421", "210.10.122.10", "pplinknet"} { responses, err := client.GetData(input) if err != nil { log.Printf("error querying %s: %v", input, err) continue } out, _ := json.MarshalIndent(responses, "", " ") log.Printf("Results for %s:\n%s\n", input, string(out)) } // Example output for "14421": // [ // { // "first_ip": "103.100.209.0", // "last_ip": "103.100.209.255", // "asn": 14421, // "country": "PK", // "org": "PPLINKNET" // } // ] } ``` -------------------------------- ### STDIN Input for asnmap Source: https://context7.com/projectdiscovery/asnmap/llms.txt Pass input types (ASN, IP, domain, organization) to asnmap via standard input. Mixed-type inputs are automatically detected. ```bash echo GOOGLE | asnmap -silent ``` ```bash # Pipe a file of mixed inputs cat targets.txt | asnmap -silent ``` -------------------------------- ### CSV Output Source: https://github.com/projectdiscovery/asnmap/blob/main/README.md The -csv flag provides output in CSV format, containing the same information as the JSON output. ```console echo hackerone.com | ./asnmap -csv -silent ``` ```csv timestamp|input|as_number|as_name|as_country|as_range 2022-09-19 12:15:04.906664007 +0530 IST|hackerone.com|AS13335|CLOUDFLARENET|US|104.16.0.0/14,104.20.0.0/16,104.21.0.0/17 2022-09-19 12:15:05.201328136 +0530 IST|hackerone.com|AS13335|CLOUDFLARENET|US|2606:4700:9760::/44 ``` -------------------------------- ### Organization to CIDR Lookup Source: https://context7.com/projectdiscovery/asnmap/llms.txt Find all CIDR ranges registered to a specific organization name. The -silent flag is used for concise output. ```bash asnmap -org GOOGLE -silent # Output: # 8.8.4.0/24 # 8.8.8.0/24 # 8.35.200.0/21 # 34.3.3.0/24 # 34.4.4.0/24 # 34.96.0.0/20 # ... ``` -------------------------------- ### MapToResults Source: https://context7.com/projectdiscovery/asnmap/llms.txt Transforms raw *Response objects into *Result structs that include human-readable timestamps, AS-prefixed ASN strings, and the full CIDR range list. This is the format used for JSON and CSV output. ```APIDOC ## MapToResults(output []*Response) ### Description Transforms raw `*Response` objects into `*Result` structs that include human-readable timestamps, AS-prefixed ASN strings, and the full CIDR range list. This is the format used for JSON and CSV output. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **results** (*Result) - A slice of enriched Result structs. ### Response Example None ``` -------------------------------- ### Convert ASN IP Ranges to CIDR Notation Source: https://context7.com/projectdiscovery/asnmap/llms.txt Converts raw ASN API responses containing first and last IP pairs into CIDR blocks using the mapcidr library. Handles potential errors during conversion. ```go package main import ( "log" asnmap "github.com/projectdiscovery/asnmap/libs" ) func main() { client, err := asnmap.NewClient() if err != nil { log.Fatal(err) } responses, err := client.GetData("AS13335") if err != nil { log.Fatal(err) } cidrs, err := asnmap.GetCIDR(responses) if err != nil { log.Fatal(err) } for _, cidr := range cidrs { log.Println(cidr.String()) // Output: // 104.16.0.0/14 // 104.20.0.0/16 // 104.21.0.0/17 // 2606:4700::/32 } } ``` -------------------------------- ### Include IPv6 CIDR Ranges Source: https://context7.com/projectdiscovery/asnmap/llms.txt By default, IPv6 CIDR ranges are excluded from plain-text output. Use the '-v6' flag to include them in the results. ```bash asnmap -org CLOUDFLARENET -silent -v6 # Output includes both IPv4 and IPv6 CIDR ranges: # 104.16.0.0/12 # 2606:4700::/32 ``` -------------------------------- ### ResolveDomain(domain string, resolvers ...string) Source: https://context7.com/projectdiscovery/asnmap/llms.txt Resolves a domain name to its IPv4 and IPv6 addresses using specified or default DNS resolvers. ```APIDOC ## ResolveDomain(domain string, resolvers ...string) ### Description Resolves a domain name to its IPv4 (A) and IPv6 (AAAA) addresses using retryable DNS. Uses Google's resolvers (8.8.8.8, 8.8.4.4) by default; custom resolvers can be passed as additional arguments. ### Usage ```go package main import ( "log" asnmap "github.com/projectdiscovery/asnmap/libs" ) func main() { // Default resolvers ips, err := asnmap.ResolveDomain("hackerone.com") if err != nil { log.Fatal(err) } log.Printf("Resolved IPs: %v", ips) // Custom resolvers ips2, err := asnmap.ResolveDomain("example.com", "1.1.1.1:53", "9.9.9.9:53") if err != nil { log.Fatal(err) } log.Printf("Resolved IPs (custom resolvers): %v", ips2) } ``` ### Example Output ``` Resolved IPs: [104.16.99.52 104.16.100.52 2606:4700::6810:6334 ...] Resolved IPs (custom resolvers): [93.184.216.34 2606:2800:220:1:248:1893:25c8:1946] ``` ``` -------------------------------- ### JSON Output Source: https://github.com/projectdiscovery/asnmap/blob/main/README.md Use the -json flag for JSON output, which is convenient for automation and post-processing. The -silent flag suppresses banner and other non-essential output. ```console echo hackerone.com | ./asnmap -json -silent | jq ``` ```json { "timestamp": "2022-09-19 12:14:33.267339314 +0530 IST", "input": "hackerone.com", "as_number": "AS13335", "as_name": "CLOUDFLARENET", "as_country": "US", "as_range": [ "104.16.0.0/14", "104.20.0.0/16", "104.21.0.0/17" ] } { "timestamp": "2022-09-19 12:14:33.457401266 +0530 IST", "input": "hackerone.com", "as_number": "AS13335", "as_name": "CLOUDFLARENET", "as_country": "US", "as_range": [ "2606:4700:8390::/44" ] } ``` -------------------------------- ### JSON Output Format Source: https://context7.com/projectdiscovery/asnmap/llms.txt Generate structured JSON output containing timestamp, input, AS number, AS name, country, and CIDR ranges. Useful for programmatic processing. ```bash echo hackerone.com | asnmap -json -silent | jq # Output: # { # "timestamp": "2022-09-19 12:14:33.267339314 +0530 IST", # "input": "hackerone.com", # "as_number": "AS13335", # "as_name": "CLOUDFLARENET", # "as_country": "US", # "as_range": [ # "104.16.0.0/14", # "104.20.0.0/16", # "104.21.0.0/17" # ] # } ``` -------------------------------- ### Query ASN Data with Custom Input Label Source: https://context7.com/projectdiscovery/asnmap/llms.txt Queries ASN data using one input but labels the results with a different string. Useful for preserving original domain names when querying by resolved IP addresses. ```go package main import ( "log" asnmap "github.com/projectdiscovery/asnmap/libs" ) func main() { client, err := asnmap.NewClient() if err != nil { log.Fatal(err) } // Query by resolved IP, but label results with the original domain responses, err := client.GetDataWithCustomInput("104.21.3.157", "hackerone.com") if err != nil { log.Fatal(err) } for _, r := range responses { log.Printf("Input: %s, ASN: %d, Org: %s", r.Input, r.ASN, r.Org) // Output: Input: hackerone.com, ASN: 13335, Org: CLOUDFLARENET } } ``` -------------------------------- ### Custom DNS Resolvers Source: https://context7.com/projectdiscovery/asnmap/llms.txt Specify custom DNS resolvers to be used for domain-to-IP resolution, overriding the default ones (8.8.8.8, 8.8.4.4). ```bash asnmap -d example.com -r 1.1.1.1:53,9.9.9.9:53 -silent ``` -------------------------------- ### Identify Input Type with IdentifyInput Source: https://context7.com/projectdiscovery/asnmap/llms.txt Classifies a string as ASN, ASNID, IP, Domain, Org, or Unknown. This function is used internally by GetData to correctly route queries. ```go package main import ( "fmt" asnmap "github.com/projectdiscovery/asnmap/libs" ) func main() { inputs := []string{"AS13335", "13335", "1.1.1.1", "cloudflare.com", "CLOUDFLARE"} for _, input := range inputs { t := asnmap.IdentifyInput(input) switch t { case asnmap.ASN: fmt.Printf("%s -> ASN\n", input) case asnmap.ASNID: fmt.Printf("%s -> ASNID\n", input) case asnmap.IP: fmt.Printf("%s -> IP\n", input) case asnmap.Domain: fmt.Printf("%s -> Domain\n", input) case asnmap.Org: fmt.Printf("%s -> Org\n", input) } } } ``` -------------------------------- ### GetCIDR(output []*Response) Source: https://context7.com/projectdiscovery/asnmap/llms.txt Converts raw API responses containing IP ranges into CIDR notation using the mapcidr library. ```APIDOC ## GetCIDR(output []*Response) ### Description Takes raw API responses containing first/last IP pairs and converts them to a slice of `*net.IPNet` CIDR blocks using the `mapcidr` library. ### Usage ```go package main import ( "log" asnmap "github.com/projectdiscovery/asnmap/libs" ) func main() { client, err := asnmap.NewClient() if err != nil { log.Fatal(err) } responses, err := client.GetData("AS13335") if err != nil { log.Fatal(err) } cidrs, err := asnmap.GetCIDR(responses) if err != nil { log.Fatal(err) } for _, cidr := range cidrs { log.Println(cidr.String()) } } ``` ### Example Output ``` 104.16.0.0/14 104.20.0.0/16 104.21.0.0/17 2606:4700::/32 ``` ``` -------------------------------- ### ASN to CIDR Lookup Source: https://context7.com/projectdiscovery/asnmap/llms.txt Retrieve all CIDR ranges associated with a given ASN number. Use the -silent flag to suppress non-essential output. ```bash asnmap -a AS45596 -silent # Output: # 103.100.209.0/24 # 103.244.220.0/22 # 202.125.154.0/24 ``` -------------------------------- ### IP to CIDR Lookup Source: https://context7.com/projectdiscovery/asnmap/llms.txt Resolve the network range (CIDR) that contains a specific IP address. The -silent flag ensures only CIDR results are displayed. ```bash asnmap -i 100.19.12.21 -silent # Output: # 100.16.0.0/12 ``` -------------------------------- ### IdentifyInput Source: https://context7.com/projectdiscovery/asnmap/llms.txt Classifies a string as one of: ASN (e.g. AS13335), ASNID (bare numeric ASN), IP, Domain, Org, or Unknown. Used internally by GetData to route the query correctly. ```APIDOC ## IdentifyInput(input string) ### Description Classifies a string as one of: `ASN` (e.g. `AS13335`), `ASNID` (bare numeric ASN), `IP`, `Domain`, `Org`, or `Unknown`. Used internally by `GetData` to route the query correctly. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **type** (string) - The identified input type (e.g., ASN, IP, Domain, Org, Unknown). ### Response Example None ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.