I have this python code from a project i'm rebasing...
def addressInNetwork(ip, net):
ipaddr = int(''.join([ '%02x' % int(x) for x in ip.split('.') ]), 16)
netstr, bits = net.split('/')
netaddr = int(''.join([ '%02x' % int(x) for x in netstr.split('.') ]), 16)
mask = (0xffffffff << (32 - int(bits))) & 0xffffffff
return (ipaddr & mask) == (netaddr & mask)
Which checks if an ip is part of a subnet... I'm not sure what exactly it does, but I do know it works... Could someone explain this to me, so that I can rewrite it in C or Assembly (depending how confident I feel lol)
User contributions licensed under CC BY-SA 3.0