Networking

Assess Internet Exposure with Shodan and cnspec

Use cnspec with Shodan to discover internet-facing services and open ports

Rely on cnspec to query Shodan search results for your hosts, revealing internet-facing services, open ports, and potential vulnerabilities across your infrastructure.

Prerequisites

To scan with Shodan using cnspec, you must have:

Give cnspec access to Shodan

Set your Shodan API key as an environment variable:

export SHODAN_API_TOKEN="your-api-key"

To retrieve your API key, go to your Shodan Account Overview.

Scan a host with Shodan

To scan a host:

cnspec scan shodan --targets HOST

For HOST, substitute the domain name or IP address. For example:

cnspec scan shodan --targets example.com

Query Shodan interactively

To open an interactive shell for exploring Shodan data:

cnspec shell shodan --targets example.com

Example queries

This query lists open ports on the host:

cnspec> shodan.host.ports
shodan.host.ports: [80, 443, 8080]

This query retrieves the organization associated with the host:

cnspec> shodan.host.org
shodan.host.org: "Example Corp"

Exit the cnspec shell

To exit the cnspec shell, either press Ctrl + D or type exit.

Learn more

On this page