Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.67 KB | None | 0 0
  1. #!/bin/bash
  2. #port scanner bash
  3. t1=0.1 # 2 msec
  4. while getopts ":h:p:" opt; do
  5.       case $opt in
  6.         h ) HOSTS="$OPTARG";;
  7.     p ) PORTS="$OPTARG";;
  8.         \? ) echo "Invalid option: -"$OPTARG"" >&2
  9.             exit 1;;
  10.         : ) echo "Option -"$OPTARG" requires an argument." >&2
  11.             exit 1;;
  12.       esac
  13.     done
  14. arrports=(${PORTS//-/ })
  15. if [[ $# -ne 4 ]];then
  16. echo "Invalid option: $@"
  17. echo "Example: ./scan.sh -h rmd5.ru -p 79-81"
  18. exit 1
  19. fi
  20. for ((i = ${arrports[0]}; i <= ${arrports[1]}; i++ )); do
  21. aaa=$(timeout $t1 bash -c "</dev/tcp/$HOSTS/$i" && echo "HOST:[$HOSTS] Port tcp $i open.")
  22. if [[ -n $aaa ]];then
  23. echo "$aaa"
  24. fi
  25. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement