Skip to content

Instantly share code, notes, and snippets.

@filippolauria
Last active April 11, 2022 10:03
Show Gist options
  • Save filippolauria/1ea3717ce68bcd31eafe3fc747e18239 to your computer and use it in GitHub Desktop.
Save filippolauria/1ea3717ce68bcd31eafe3fc747e18239 to your computer and use it in GitHub Desktop.
A simple bash one-liner that, relying on nmap and snmpget, scans for available printers on a given network. The results are sent to standard output and saved in the /tmp directory.
N="192.168.1.0/24" && \
H=$(sudo nmap -sS -sU -T5 -PE -pU:524,631,8611-8614,T:515,524,631,8611-8614,9100 -oG - --open -n $N | grep "/open" | cut -d' ' -f2 | tr '\n' ' ') && \
for p in $(sudo nmap -Pn -T5 -sU -p 161 -oG - --open -n $H | grep "/open" | cut -d' ' -f2); do \
S=$((snmpget -v1 -Ov -cpublic -t0.5 $p .1.3.6.1.2.1.1.1.0 | sed 's/^STRING:\s\+//') 2> /dev/null); \
if [ "$S" ]; then echo -e "$p\t: $S"; fi; \
done | tee /tmp/`date '+%Y-%m-%d'`-printers.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment