Skip to content

Instantly share code, notes, and snippets.

@jsidhu
Created April 11, 2017 05:16
Show Gist options
  • Save jsidhu/f17d0d7db46d0625bfaab935e294143c to your computer and use it in GitHub Desktop.
Save jsidhu/f17d0d7db46d0625bfaab935e294143c to your computer and use it in GitHub Desktop.

Revisions

  1. jsidhu created this gist Apr 11, 2017.
    11 changes: 11 additions & 0 deletions port_check.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    #!/bin/bash

    HOST=$1
    PORT=$2
    timeout 1 bash -c "cat < /dev/null > /dev/tcp/${HOST}/${PORT}"
    RESULT=$?
    if [ "${RESULT}" -ne 0 ]; then
    echo "Failed: ${RESULT}"
    else
    echo "Connected: ${RESULT}"
    fi