Last active
July 31, 2020 22:08
-
-
Save JFFail/0bf09eba6ea20e69384e to your computer and use it in GitHub Desktop.
Script to repeatedly check port availability on an endpoint. Takes server name and a port number as parameters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ $# -ne 2 ]]; then | |
echo "Please submit 2 arguments: server name and port number" | |
else | |
total=0 | |
success=0 | |
while true; do | |
total=$((total+1)) | |
result=$(nmap -Pn -p $2 $1 | grep "/tcp") | |
echo -n $result | |
open=$(echo $result | awk '{print $2}') | |
if [[ $open == "open" ]]; then | |
success=$((success+1)) | |
fi | |
length=$(echo $result | wc -c) | |
if [[ $total -eq 1 ]]; then | |
baseline=$length | |
elif [[ $length -lt $baseline ]]; then | |
baseline=$length | |
fi | |
percent=$(echo "scale=2;100*$success/$total" | bc) | |
if [[ $length -gt $baseline ]]; then | |
echo -e " > \t$success / $total - $percent% " | |
else | |
echo -e " > \t\t$success / $total - $percent%" | |
fi | |
sleep 5 | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment