PDA

View Full Version : [Solved] Determining if your IP address is in a certain range


fonz
February 19th, 2009, 02:35
Howdy,

I'm toying with the following: I'd like to check whether or not my IP address starts with xxx.yyy and if not, launch openvpn.

I could of course do something likecase `ifconfig rum0|grep inet|awk '{print $2}'` in
xxx.yyy.*) ;;
*) openvpn /etc/openvpn.conf
;;
esacbut I was wondering if there is a more elegant way.

Suggestions are welcome,

Alphons

Mel_Flynn
February 19th, 2009, 09:05
Don't think it gets more elegant then that (maybe add head -1 in case you have aliases). Where you put it, is the better question. My choice would be /etc/dhclient-exit-hooks. Look at /sbin/dhclient-script and man dhclient-script for more info.
When not via dhcp, maybe hook into devd?

fonz
February 22nd, 2009, 18:25
Where you put it, is the better question. My choice would be /etc/dhclient-exit-hooks.

Thanks, I hadn't considered that. It was going to go into /etc/rc.local for lack of a better idea, but your suggestion is much better.

Alphons