Skip to content

Instantly share code, notes, and snippets.

@smj10j
Created August 26, 2016 04:02
Show Gist options
  • Select an option

  • Save smj10j/0a216492ce09c4c88fcdc329b7cd205d to your computer and use it in GitHub Desktop.

Select an option

Save smj10j/0a216492ce09c4c88fcdc329b7cd205d to your computer and use it in GitHub Desktop.
Redirects local ports on the fly
ROUTER="ncat --sh-exec 'ncat $(sudo route -n get default -interface utun0 | sed -nre 's/.*?gateway: (.*?)$/\1/p') 7200' \
--wait 30 \
--output ncat-forward-tcp.dump \
--verbose \
--listen 10020 "
pids=""
CMD=$(echo ${ROUTER}{'& ; pids="$pids $!"; ','--udp & ; pids="$pids $!"; '})
eval "$CMD"
KILLPIDS() {
foreach p in $(echo "( $pids )"); do kill -9 $p; done
}
trap KILLPIDS QUIT INT ERR
wait %2 %2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment