Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: Bash  |  size: 0.70 KB  |  hits: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2.  
  3. UH=$1
  4. shift
  5.  
  6. regex="\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"
  7.  
  8. tmp="$(echo $UH | cut -d@ -f2)"
  9. ip="$(echo $tmp | cut -d: -f1)"
  10. port="$(echo $tmp | cut -d: -f2)"
  11.  
  12. if [[ -z $(echo $ip | egrep $regex) ]];
  13. then
  14.         ip="$(host $ip | head -1 | cut -d' ' -f4)"
  15. fi
  16.  
  17. echo $ip;
  18. for ARG in "$@"
  19. do
  20. {
  21.         echo "Testing $ip:$ARG"
  22.         if ! exec 3<> /dev/tcp/$ip/$ARG; then
  23.                 echo 0
  24.         else
  25.                 echo 1
  26.         fi
  27. } 2> /dev/null | {
  28.         while true; do
  29.                 read line || break
  30.                 case $line in
  31.                         0) echo " [CLOSED]" ;;
  32.                         1) echo " [OPEN]" ;;
  33.                         *) echo -n $line ;;
  34.                 esac
  35.         done
  36. }
  37. done