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
1 |
nmap -sL 192.168.0.* |
Using grep and -v with a Regular Expression it suppress the IP scanned that have no hostname
1 |
grep -v "^Nmap scan report for 192.168.0." |
replace remove the unwanted text
1 |
replace "Nmap scan report for " "" |
or even better with sed
1 |
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:
1 2 3 4 5 6 7 8 9 10 11 12 |
#!/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 <span class="pl-s"><span class="pl-pds">'</span>s/Nmap scan report for //g<span class="pl-pds">'</span></span>| tee $REPORT_FILENAME echo "--- $REPORT_FILENAME has been created! ---" |