Configure Cntlm to use no proxy if none are available

I am behind a corporate firewall in the day, and on an open internet connection at night. I have configured cntlm to forward to my corporate proxy, but when I connect from an open connection, I must re-configure my proxy settings.

Is there a way to make cntlm fallback to using no proxy when there is none available?

# List of parent proxies to use. More proxies can be defined
# one per line in format <proxy_ip>:<proxy_port>
#
Proxy       10.73.55.44:80
# <~~ something here to fallback to a direct connection when no proxy is available

Solution 1:

cntlm has this on it's roadmap, but I think I solved this problem in a simple way using squid: 1. Install squid on the same machine as cntlm, on port 3129 (just change 3128 to 3129 in squid.conf) 2. Add "Proxy localhost:3129" to the cntlm proxy list

That's it.

Hope this helps.

Solution 2:

This solution rewrites the relevant part of the cntlm.conf based on your current IP address: http://mirkoweber.blogspot.hu/2011/10/using-cntlm-in-changing-environment.html

#!/bin/sh
case "$2" in
    up|vpn-up)
          IP=`/sbin/ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`
          case $IP in
             172.*)
                logger "setNoProxy.sh -set NoProxy for enterprise net"
                NoProxy="NoProxy         localhost, 127.0.0.*, 10.*, 192.168.*,enterprise-intranet"
                ;;
               *)
                logger "setNoProxy.sh - set NoProxy for direct net"
                NoProxy="NoProxy *"
                ;;
            esac
         sudo sed "s/^NoProxy.*$/$NoProxy/g" -i /etc/cntlm.conf
         sudo service cntlm restart
         ;;
esac