Created
July 30, 2020 20:37
-
-
Save hradec/138f576069f3017c59ca9e8daae083db to your computer and use it in GitHub Desktop.
A simple script to cleanup duplicated entries in a UPNP Server using upnpc!
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 | |
| # to speed up the execution by not having to probe the network for the upnp server | |
| # or if you have more than one upnp server in your network, | |
| # use upnp_url var to specify the url of your upnp server. | |
| # to find all the upnp servers urls, you can run: | |
| # upnpc -l | grep 'InternetGatewayDevice' -B 1 | grep 'desc:' | |
| #upnp_url="http://192.168.10.1:6352/rootDesc.xml" | |
| [ "$upnp_url" != "" ] && upnp_url="-u $upnp_url" | |
| upnpc="/usr/bin/upnpc $upnp_url" | |
| duplicated=$($upnpc -l | awk '{print $2"@"$3}' | egrep 'TCP|UDP' | sort | uniq -d) | |
| if [ "$duplicated" != "" ] ; then | |
| echo "List of duplicated entries..." | |
| echo "$duplicated" | |
| echo "Removing duplicated entries..." | |
| for n in $duplicated ; do | |
| protocol=$(echo $n | awk -F'@' '{print $1}') | |
| port=$(echo $n | awk -F'@' '{print $2}' | awk -F'->' '{print $1}' ) | |
| echo $upnpc -d $port $protocol | |
| $upnpc -d $port $protocol | |
| done | |
| fi | |
| $upnpc -l | awk '{print $3" \t"$2}' | egrep 'TCP|UDP' | sort -h | sed 's/->/\t -> /g' | sed 's/:/\t : /g' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment