Skip to content

Instantly share code, notes, and snippets.

@cbowdon
Created January 4, 2019 17:20
Show Gist options
  • Save cbowdon/a07c56693d07c97286715a81e572ec1d to your computer and use it in GitHub Desktop.
Save cbowdon/a07c56693d07c97286715a81e572ec1d to your computer and use it in GitHub Desktop.
Poor man's intercepting proxy
#!/usr/bin/env bash
# Thanks to https://blog.hawkhost.com/2009/12/12/using-netcat-as-an-intercepting-proxy/
server=${1:-localhost}
localport=${2:-8080}
remoteport=${3:-$localport}
pipe=intercepting-proxy.pipe
# shellcheck disable=SC2094
rm -f "$pipe" &&
mkfifo "$pipe" &&
echo "listening for localhost:${localport} to proxy to ${server}:${remoteport}..." &&
nc -k -l -p "$localport" < "$pipe" | tee proxy-requests.log | nc "$server" "$remoteport" | tee "$pipe" proxy-responses.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment