Determining if your IP address is in a certain range

fonz

Son of Beastie

Reaction score: 369
Messages: 2,560

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 like
Code:
case `ifconfig rum0|grep inet|awk '{print $2}'` in
  xxx.yyy.*) ;;
  *) openvpn /etc/openvpn.conf
     ;;
esac
but I was wondering if there is a more elegant way.

Suggestions are welcome,

Alphons
 

Mel_Flynn

Well-Known Member

Reaction score: 81
Messages: 379

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?
 
OP
OP
F

fonz

Son of Beastie

Reaction score: 369
Messages: 2,560

Mel_Flynn said:
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
 
Top