Local Resource

If your needs are simple you can use a little of this ip math.

First something to show a printed representation of a binary string for python:

#show binary rep of an int
bstr_pos = lambda n: n>0 and bstr_pos(n>>1)+str(n&1) or ''

Now let's use that to see a netmask of a 24 bit mask (i.e. 255.255.255.0)

>>> bstr_pos = lambda n: n>0 and bstr_pos(n>>1)+str(n&1) or ''
>>> nomask = (2**32)-1
>>> mask = lambda x: nomask^(2**(32-x)-1)
>>> bstr_pos(mask(24))
'11111111111111111111111100000000'

Other Resource

As your needs get more complicated you can look to other python packages.

IPy includes a __contains__ operator so you can make calls like:

>>> '127.0.0.1' in IP('127.0.0.0/24')
1

very handy.