Ξ welcome to cryptostorm's member forums ~ you don't have to be a cryptostorm member to post here Ξ
Ξ any OpenVPN configs found on the forum are likely outdated. For the latest, visit here or GitHub Ξ
Ξ If you're looking for tutorials/guides, check out the new https://cryptostorm.is/#section6 Ξ

Automating Port Forwarding?

Looking for assistance with a cryptostorm connection issue? Post here & we'll help out. Also: if you're not sure where to post, do so here & we'll move things around as needed. Also: for quickest support, email our oddly calm & easygoing support reps at support@cryptostorm.is :)

Topic Author
Oriman

Automating Port Forwarding?

Post by Oriman » Tue May 14, 2019 7:45 pm

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!

User avatar

df
Site Admin
Posts: 411
Joined: Thu Jan 01, 1970 5:00 am

Re: Automating Port Forwarding?

Post by df » Wed May 15, 2019 2:35 pm

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:

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
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.


Topic Author
Oriman

Re: Automating Port Forwarding?

Post by Oriman » Thu May 16, 2019 12:25 am

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?

User avatar

df
Site Admin
Posts: 411
Joined: Thu Jan 01, 1970 5:00 am

Re: Automating Port Forwarding?

Post by df » Mon May 20, 2019 2:28 am

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.

Post Reply