Monthly Archives: August 2015

[Bash Script] Transmission bind to an VPN Interface / Ip Address

Here is a short bash script to bind transmission (Bit Torrent Client) to the ip of an interface (VPN) . Incase the ip changes you should run this in an Cronjob , if the ip changes it adds the new ipv4 bind adress to settings.json and restarts the transmission daemon.

currentip=$(grep ipv4 /Transmission/conf/settings.json | awk -F\” ‘{ print $4 }’)
#echo $currentip

newip=$(ifconfig tun0 | grep ‘inet addr:’ | cut -d: -f2| cut -d’ ‘ -f1)
#echo $newip

if ifconfig tun0 >>/dev/null 2>&1; then

if [ “$currentip” = “$newip” ]; then
exit
else
sed -i “s/\”bind-address-ipv4\”:.*\$/\”bind-address-ipv4\”: \”$(ifconfig tun0 | grep ‘inet addr:’ | cut -d: -f2| cut -d’ ‘ -f1)\”,/” /share/HDA_DATA/.qpkg/Transmiss$

bash /etc/init.d/transmission.sh restart
fi
fi

 

Replace /Transmission/conf/settings.json with the location of your settings.json and tun0 with the interface Name.

 

[download id=”24″¬†format=”2″]