Skip to content

Instantly share code, notes, and snippets.

@mbierman
Created March 9, 2022 21:12
Show Gist options
  • Select an option

  • Save mbierman/b694f963f7e32581b040f084082046ff to your computer and use it in GitHub Desktop.

Select an option

Save mbierman/b694f963f7e32581b040f084082046ff to your computer and use it in GitHub Desktop.
See if there is a TCP port open at an IP
#!/bin/bash
ip=$1
port=$2
# port=${2:-5001}
if [[ $ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]] && [[ $port =~ ^[0-9]* ]] ; then
nc -vnz $ip $port
exit
else
echo -e "Sorry you have to enter an IP and port?\n\n $(basename $0) [xxx.xxx.xxx.xxx port]"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment