Use the Netshot API to scan a subnet of devices

Netshot exposes most of its features to third-party or own-made scripts via a REST API.

Here is a very quick example on how to start a scanning task. Let's use cURL to pass the REST commands, from the Linux command line -- in real life the same REST commands would probably be initiated from a Python or Perl script. We're going to ask Netshot to scan the subnet 10.16.16.0/24 in order to discover network devices. That's the programmatic equivalent to the Scan subnet(s) for devices option in the Add device... menu within the Netshot web UI.

Let's assume the Netshot server is available on https://netshotserver:8443/, and the read-write account to use is script with a password of automation.

  1. Authentication:

    $ curl -k -v -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{ "username": "script", "password": "automation" }' https://netshotserver:8443/api/user

    Note down the authentication cookie: JSESSIONID=[the ID].
  2. Schedule the scan task, to run immediately:

    $ curl -k -v -X POST -H "Content-Type: application/json" -H "Accept: application/json" -H "Cookie: JSESSIONID=[the ID from step 1]" -d '{ "type": "ScanSubnetsTask", "domain": "1", "subnets": "10.16.16.0/24" }' https://netshotserver:8443/api/tasks

  3. (Optional) Close the session:

    $ curl -k -v -X DELETE -H "Accept: application/json" -H "Cookie: JSESSIONID=[the ID from step 1]" https://netshotserver:8443/api/user/0

Netshot should start scanning the devices in the provided subnet, using the SNMP credentials it knows about. Any new device will be added to the DB and further discovered (configuration snapshot, compliance check, etc.).

Note: The REST calls were done using JSON format, but XML is equally supported.