Solved: Algorithm for default port forwarding calculator

f00fup

New Member
Hi,

I'm trying to create a bash script on a Linux host that brings up a Perfect-Privacy VPN connection then uses the default port forwarding to run a listening service. Unfortunately, it's not clear to me how the default port forwarding ports are calculated by the port forwarding calculator. Can you share the algorithm and a way to calculate the default ports in a script?

Thanks!
 

MixMaster

Member
I use the following bash construct in an OpenVPN up-script. It's certainly not pretty but does the job:

Code:
ifconfig_local_ip="$4"

p1="`echo "$ifconfig_local_ip" |sed -e 's/.*\.\([0-9]*\)\.\([0-9]*\)$/\1/'`"
p2="`echo "$ifconfig_local_ip" |sed -e 's/.*\.\([0-9]*\)$/\1/'`"

port="`printf "1%04d" "$(( (($p1 % 0x10) * 256) + $p2 ))"`"
 
Last edited:
Top