Feb.02
Fedora/Redhat Change proxy based on IP detection
HI All, i am giving some to tricks to simplify life of a Linux desktop user.
In my office environment , all networks are based on Class A and in home Class C. So everytime changing the proxy was little difficult for me. and finally i wrote something like below.
This will detect the IP class and change the system wide proxy.
#!/bin/bash
export DISPLAY=:0.0
IP_ADDRESS=$(ip addr | grep ‘state UP’ -A2 | tail -n1 | awk ‘{print $2}’ | cut -f1 -d’/’)
#echo $IP_ADDRESS
IP_CLASS=$(/usr/bin/ipcalc $IP_ADDRESS| egrep “Address class:” | awk ‘{print $3$4}’)
if [ $IP_CLASS == “ClassA” ];then
echo “Class A IP”
gsettings set org.gnome.system.proxy mode ‘manual’
gsettings set org.gnome.system.proxy.http host ‘proxy.example.com’
gsettings set org.gnome.system.proxy.http port 1234
gsettings set org.gnome.system.proxy.https host ‘proxy.example.com’
gsettings set org.gnome.system.proxy.https port 1234
gsettings set org.gnome.system.proxy.ftp host ‘proxy.example.com’
gsettings set org.gnome.system.proxy.ftp port 1234
gsettings set org.gnome.system.proxy.socks host ‘proxy.example.com’
gsettings set org.gnome.system.proxy.socks port 1234
else
echo “Class C”
gsettings set org.gnome.system.proxy mode ‘none’
EOF
i know this is not a neat script. But you can get some idea and develop more from this. 🙂
Prince
Okay i will try my level best to get some new idea