Skip to content

Instantly share code, notes, and snippets.

@cfeduke
Created November 18, 2014 15:21
Show Gist options
  • Save cfeduke/9ea5e170e6766e53ca68 to your computer and use it in GitHub Desktop.
Save cfeduke/9ea5e170e6766e53ca68 to your computer and use it in GitHub Desktop.
Generate command for forwarding Windows local port to OSX host for accessing OSX hosted web application as localhost
#!/usr/bin/env bash
# Prints out the Windows netsh command necessary to port forward on localhost to another
# IP address. Especially useful when testing IE11 with APIs like Google Maps that only
# permit localhost connectivity but the actual server is on your local OSX host machine
# usage:
# netsh [interface] [port]
#
# e.g.,
# netsh en0 8080 | pbcopy
set -o nounset
set -o errexit
IFACE=${1:-en0}
PORT=${2:-3000}
IP=$(/sbin/ifconfig $IFACE | grep "inet\b" | cut -d " " -f2)
if [ -z "$IP" ]; then
echo unable to determine IP address from interface $IFACE
exit 1
fi
echo netsh interface portproxy add v4tov4 listenport=$PORT listenaddress=127.0.0.1 connectport=$PORT connectaddress=$IP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment