BaSH and NMap to list all devices connected to a guest wi-fi network

Monitoring your network resources and infrastructure effectively requires planning, knowledge of the metrics and experience of how to set up the threshold for warning and critical alarms and a lot of testing.

It’s very hard to focus on signals where there is too much noise.

Usually the tool you’re using doesn’t matter so much, what it’s really important what to implement more than how. And even if the configuration and the design are different we should be able to achieve similar results.

In this example I use a very popular tool such NMAP and with BaSH create a plain text report of a guest wi-fi network that sometime I want to generate.

The script uses nmap with a subnet and -sL: List Scan which simply list targets to scan

nmap -sL 192.168.0.*

Using grep and -v with a Regular Expression it suppress the IP scanned that have no hostname

grep -v "^Nmap scan report for 192.168.0."

replace remove the unwanted text

 replace "Nmap scan report for " ""

or even better with sed

sed -e 's/Nmap scan report for //g'

and tee creates an output file from all input passed from the previous commands. I’ve added a couple of variable to edit the subnet and the report name.

This is the final script also available on github:

#!/bin/bash
#
# This scripts uses and requires NMAP, creates a report with all host connected to the SUBNET
#
# author: [email protected] , https://www.scriptinglibrary.com

# CONFIGURE ACCORDING TO YOUR NEEDS
REPORT_FILENAME="scan-$(date +%Y-%m-%d).txt"
WIFI_SUBNET="192.168.0"

nmap -sL $WIFI_SUBNET.* | grep -v "^Nmap scan report for $WIFI_SUBNET" | sed -e 's/Nmap scan report for //g'| tee $REPORT_FILENAME
echo "--- $REPORT_FILENAME has been created! ---"

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.