Networking
Scan Networks with Nmap and cnspec
Discover hosts, open ports, and services using Nmap with cnspec
Discover hosts, open ports, and running services across your network infrastructure using cnspec and the Nmap network scanner.
Prerequisites
To scan networks with cnspec and Nmap, you must have:
Scan a network or host
To scan a single host:
cnspec shell nmap 192.168.1.1To scan a network range using CIDR notation:
cnspec shell nmap 192.168.1.0/24To scan multiple networks:
cnspec shell nmap --networks 10.0.0.0/8,192.168.0.0/16Example queries
Once connected, you can query Nmap scan results.
List all discovered hosts
cnspec> nmap.network.hosts
nmap.network.hosts: [
0: nmap.host name="192.168.1.1"
1: nmap.host name="192.168.1.100"
...
]Retrieve the Nmap version
cnspec> nmap.version
nmap.version: {
version: "7.94"
...
}Find all hosts with open SSH ports
cnspec> nmap.network.hosts.where(ports.one(port == 22 && state == "open"))List all open ports across all hosts
cnspec> nmap.network.hosts { name ports.where(state == "open") { port protocol service } }Learn more
-
To learn more about how the MQL query language works, read Write Effective MQL.
-
For a list of all the Nmap resources and fields you can query, read the Nmap Resource Pack Reference.