Networking
Query IP Information with cnspec
Query IP address information from ipinfo.io with cnspec.
Query IP address information from the ipinfo.io service with cnspec. Use the IPinfo provider inside your own policies to check whether IPs in your environment match expected geographies, organizations, or routability.
Prerequisites
To query IP information with cnspec, you must have:
- cnspec 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
Open a cnspec shell with the IPinfo provider:
cnspec shell ipinfoOr run one-off queries:
# Query information about a specific IP
cnspec run ipinfo -c "ipinfo(ip('8.8.8.8')){*}"
# Query your machine's public IP
cnspec run ipinfo -c "ipinfo(){*}"
# Query IP information for all network interfaces
cnspec run -c "network.interfaces.map(ips.map(_.ip)).flat.map(ipinfo(_){*})"Example queries
Retrieve your public IP information
cnspec> ipinfo()
ipinfo: {
returned_ip: "203.0.113.50"
hostname: "example.host.com"
city: "San Francisco"
...
}Retrieve information about a specific IP
cnspec> 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"
...
}Check if an IP is a bogon (private/non-routable)
cnspec> ipinfo(ip("192.168.1.1")).bogon
ipinfo.bogon: 1Retrieve the organization managing an IP
cnspec> ipinfo(ip("1.1.1.1")).org
ipinfo.org: "AS13335 Cloudflare, Inc."Learn more
- IPinfo Resource Pack Reference: every IPinfo resource and field cnspec can query
- Write Effective MQL: guide to authoring checks and queries