Skip to content

Instantly share code, notes, and snippets.

@cfeduke
Created Nov 18, 2014
Embed
What would you like to do?
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