# Determining if your IP address is in a certain range



## fonz (Feb 19, 2009)

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
	
	



```
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 (Feb 19, 2009)

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 (Feb 22, 2009)

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


----------

