Hello there,
is there any way of automating port forwarding? I've written a bash script that automates VPN reconnection in case of a connection drop, but I have been unable to automate port forwarding for multiple ports.
For a single port I've written a simple userscript that automates the input of the port into the website form, but I am unable to do it for multiple ports. It'd also be easier if it could be done from the commandline (by e.g. sending a specific packet).
Thanks in advance!
Automating Port Forwarding?
Re: Automating Port Forwarding?
The page on http://10.31.33.7/fwd only accepts a single port per request, so your script would need to do it multiple times per port.
Since you're using a script to connect to the VPN, you could add something like this that would run after being connected:
Replace 31340, 31341, and 31342 with the actual ports you want to use, then have your VPN connecting script call the one above after connecting (or just embed the above code into your script, minus the #!/bin/bash).
You could also add better error reporting to the bit after resp= so that instead of just echoing errors (like if a port's already in use or the connection to 10.31.33.7 times out, or whatever), you could instead have it email you or send the error to a logfile, etc.
Since you're using a script to connect to the VPN, you could add something like this that would run after being connected:
Code: Select all
#!/bin/bash
declare -a ports=(
31340
31341
31342
)
for port in "${ports[@]}"; do
resp=`wget -T4 -t1 -qO- http://10.31.33.7/fwd --post-data="port=$port"`
if [ $? != 0 ] || [[ `echo $resp|grep Error:` ]]; then
echo "Port $port $resp"|head -n1|sed -e's/<.*//'
exit 1
fi
echo $resp|sed -e's/<.*//'
done
exit 0
You could also add better error reporting to the bit after resp= so that instead of just echoing errors (like if a port's already in use or the connection to 10.31.33.7 times out, or whatever), you could instead have it email you or send the error to a logfile, etc.
Re: Automating Port Forwarding?
Thanks for the response!
After digging for a while longer I've found out that it's also possible to do it using curl. Is there any significant advantage in using wget over curl?
After digging for a while longer I've found out that it's also possible to do it using curl. Is there any significant advantage in using wget over curl?
Re: Automating Port Forwarding?
Not really, they both perform the same task. It's just that it's Linux, so there's more than one way to do the same thing.