Advertisement
Guest User

Untitled

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