Created
March 30, 2019 02:13
-
-
Save mvadu/44c55b05d4614cf07d9833e0b44bf27a to your computer and use it in GitHub Desktop.
THis script uses upnp client (upnpc) to talk to router and open ports
This file contains hidden or 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 | |
#~/bin/upnpPortMapper.sh | |
#sudo apt-get install miniupnpc | |
#crontab -l | grep upnp || echo $(crontab -l ; echo '*/5 * * * * ~/bin/upnpPortMapper.sh >/dev/null 2>&1') | crontab - | |
export LC_ALL=C | |
router=$(ip r | grep default | cut -d " " -f 3) | |
gateway=$(upnpc -l | grep "desc: http://$router:[0-9]*/rootDesc.xml" | cut -d " " -f 3) | |
ip=$(upnpc -l | grep "Local LAN ip address" | cut -d: -f2) | |
external=80 | |
port=80 | |
upnpc -u $gateway -d $external TCP | |
upnpc -u $gateway -e "Web mapping for RaspberryPi" -a $ip $port $external TCP | |
external=443 | |
port=443 | |
upnpc -u $gateway -d $external TCP | |
upnpc -u $gateway -d $external UDP | |
upnpc -u $gateway -e "TLS Web mapping for RaspberryPi" -a $ip $port $external TCP |
Router and gateway dont seem to be needed. Still, a useful gist.
Router and gateway dont seem to be needed. Still, a useful gist.
You would need them if you happen to have more than one UPNP servers which broadcasts own self. In that case script checks where it got the IP, and generates a upnp gateway url.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is awesome, I've been try work this out for days, ive added it to my domoticz.sh file and it works a treat. Many Thanks mvadu.