Query IP Information
Query IP address information from ipinfo.io with cnquery
Rely on cnquery to query IP address information from the ipinfo.io service. Get geolocation data, hostname information, and organization details for any IP address.
Requirements
To query IP information with cnquery, you must have:
- cnquery installed on your workstation.
- Internet access to reach the ipinfo.io API.
Optionally, set the IPINFO_TOKEN environment variable for authenticated API access with higher rate limits.
Query IP information
To open a cnquery shell with the ipinfo provider:
cnquery shell ipinfoYou can also run one-off queries:
# Query information about a specific IP
cnquery run ipinfo -c "ipinfo(ip('8.8.8.8')){*}"
# Query your machine's public IP
cnquery run ipinfo -c "ipinfo(){*}"
# Query IP information for all network interfaces
cnquery run -c "network.interfaces.map(ips.map(_.ip)).flat.map(ipinfo(_){*})"Example queries
Once in the cnquery shell, you can query IP information.
This query retrieves information about your public IP:
cnquery> ipinfo()
ipinfo: {
returned_ip: "203.0.113.50"
hostname: "example.host.com"
city: "San Francisco"
...
}This query retrieves information about a specific IP:
cnquery> ipinfo(ip("8.8.8.8"))
ipinfo: {
returned_ip: "8.8.8.8"
hostname: "dns.google"
city: "Mountain View"
region: "California"
country: "US"
org: "AS15169 Google LLC"
...
}This query checks if an IP is a bogon (private/non-routable address):
cnquery> ipinfo(ip("192.168.1.1")).bogon
ipinfo.bogon: 1This query retrieves the organization managing an IP:
cnquery> ipinfo(ip("1.1.1.1")).org
ipinfo.org: "AS13335 Cloudflare, Inc."Exit the cnquery shell
To exit the cnquery shell, either press Ctrl + D or type exit.
Learn more
-
To learn more about how the MQL query language works, read Write Effective MQL.
-
For a list of all the IPinfo resources and fields you can query, read the IPinfo Resource Pack Reference.