daily pastebin goal
44%
SHARE
TWEET

Untitled

a guest Dec 11th, 2018 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. scan() {
  2.   if [[ -z $1 || -z $2 ]]; then
  3.     echo "Usage: $0 <host> <port, ports, or port-range>"
  4.     return
  5.   fi
  6.  
  7.   local host=$1
  8.   local ports=()
  9.   case $2 in
  10.     *-*)
  11.       IFS=- read start end <<< "$2"
  12.       for ((port=start; port <= end; port++)); do
  13.         ports+=($port)
  14.       done
  15.       ;;
  16.     *,*)
  17.       IFS=, read -ra ports <<< "$2"
  18.       ;;
  19.     *)
  20.       ports+=($2)
  21.       ;;
  22.   esac
  23.  
  24.  
  25.   for port in "${ports[@]}"; do
  26.     alarm 1 "echo >/dev/tcp/$host/$port &&
  27.       echo \"port $port is open\"" ||
  28.       echo "port $port is closed"
  29.   done
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top