Zuletzt geändert: Mi, 15.09.2004

«11C» revtel.sh «PDF», «POD»



Download
#!/bin/sh

bipipe() {
  local FIFO=/tmp/.bipipe.$$
  rm -f "$FIFO"
  mkfifo "$FIFO" || return

  bash -c "$1" < "$FIFO" | \
  bash -c "$2" > "$FIFO"
}

prompt() {
  local PROMPT=$1 VARNAME=$2

  read -p "$PROMPT: " $VARNAME
  REPLY=`eval echo '$'$VARNAME`

  read -p "You selected '$REPLY' for $VARNAME. Correct (y/n)? "
  if [ "$REPLY" = "y" ]; then
    return
  else
    prompt "$PROMPT" "$VARNAME"
  fi
}

prompt "Netcat command" NC
prompt "Retry interval" RETRY_VAL
prompt "Timeout"        TIMEOUT

select TYPE in server client; do
  if [ "$TYPE" = "server" ]; then
    prompt "Source host" SRC_HOST
    prompt "Source port" SRC_PORT
    prompt "Dest host"   DEST_HOST
    prompt "Dest port"   DEST_PORT

    while
      :
    do
      bipipe "$NC -vw '$TIMEOUT' '$SRC_HOST' '$SRC_PORT'" \
             "$NC -vw '$TIMEOUT' '$DEST_HOST' '$DEST_PORT'"
      sleep "$RETRY_VAL"
    done
  else
    prompt "Dest port"      DEST_PORT
    prompt "Listening port" DEST_LPORT

    while
      :
    do
      bipipe "$NC -vlw '$TIMEOUT' -p '$DEST_PORT'" \
             "$NC -vlw '$TIMEOUT' -p '$DEST_LPORT'"
      sleep "$RETRY_VAL"
    done
  fi
done