Last active
March 24, 2018 18:15
-
-
Save revington/afa730d1036677fc030e to your computer and use it in GitHub Desktop.
upnp set up script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export IP=$(/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}') | |
echo "setting up ip ${IP}" | |
check_service(){ | |
echo `upnpc -l | grep $1'->' | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"` | |
} | |
register(){ | |
local service_name=$1 | |
local port=$2 | |
local forward_port=$3 | |
local protocol=$4 | |
local existing=$(check_service $forward_port) | |
if [ -z $existing ] | |
then | |
echo "registering $service_name" | |
upnpc -a ${IP} ${port} ${forward_port} ${protocol} > /dev/null | |
elif [ "$existing" != "$IP" ] | |
then | |
echo "unregistering $service_name from '$existing'" | |
upnpc -d ${forward_port} ${protocol} > /dev/null | |
echo 'registering transmission' | |
upnpc -a ${IP} ${port} ${forward_port} ${protocol} > /dev/null | |
else | |
echo "$service_name already configured" | |
fi | |
} | |
register ssh 22 2200 TCP | |
register transmision_web_ui 9091 9091 TCP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment