Skip to content

Instantly share code, notes, and snippets.

@AgustinParmisano
Last active April 17, 2018 04:05
Show Gist options
  • Save AgustinParmisano/2bdc2b49285e3f22ce621927794cf5eb to your computer and use it in GitHub Desktop.
Save AgustinParmisano/2bdc2b49285e3f22ce621927794cf5eb to your computer and use it in GitHub Desktop.
host port scan with netcat
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: port"
exit 1
fi
local_ip=$(ifconfig | grep "inet " | tail -1 | awk -F ' ' '{print $2}')
port=$1
ips=($(fping -g $local_ip/24 2> /dev/null | grep alive | cut -d" " -f1 | sed -n '1!p'))
for ip in $ips; do
nc -vz $ip $port 2>&1 | grep succeeded | awk -F ' ' '{print $3}'
if [ $? -eq 0 ]; then
echo "[+] Host $ip has port $port open!"
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment