Ξ 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?

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbdown: :thumbup: :wave: :wtf: :yawn:

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

If you wish to attach one or more files enter the details below.

Expand view Topic review: Automating Port Forwarding?

Re: Automating Port Forwarding?

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.

Re: Automating Port Forwarding?

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?

Re: Automating Port Forwarding?

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.

Automating Port Forwarding?

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!

Top