Script snippet that detects private IP addresses

Hello all,

I am looking for a script, or part of a script that can detect private RFC 1918 addresses in the 10.0.0.0/8 172.16.0.0/12 and 192.168.0.0/16 ranges.

Has anyone got something handy? I’m guessing it just needs to parse the first to octets, but it’s a bit beyond my scripting capabilities.

Any help would be appreciated.

Ahh ok, that’s great. Just what I need!

Are there any other uses for the ‘in’ function?