root/hodgestar/PythonCode/SmallScripts/ip.py

Revision 375, 302 bytes (checked in by simon, 4 years ago)

Miscellaneous small scripts.

  • Property svn:mime-type set to text/python-source
  • Property svn:eol-style set to native
Line 
1def ipToLong(sIp):
2    a = sIp.split('.')
3    a.reverse()
4    i = 0
5    l = long(0)
6   
7    for s in a:
8        l += long(s) << i
9        i += 8
10       
11    return l
12
13def isIpIn(sIp,sNet,iMask):
14   lIp = ipToLong(sIp) >> (32-iMask)
15   lNet = ipToLong(sNet) >> (32-iMask)   
16   return lIp == lNet
17   
Note: See TracBrowser for help on using the browser.