networking - How can I check if an ip is in a network in python -
Looking at an IP address (19 2.168.0.1), how do I check that it is in the network (19 2.168 .0.0 / 24) in Python?
Is there general tool in Python for IP address manipulation? Content like host lookups, IP adddress for int, network address with netmask on the net and so on? Hope for standard 2.5 in the Python Library.
shows that you can do much more with it without having to do more modules. I added a bit for this article:
import socket, def def makeMask (n): "return a mask of n bits as long bit integer" (2L incorrect truth
If you Now, "there is an address in a network" ipaddr = struct.unpack ('a network has an address'): L', socket.inet_aton (IP)) [0] NetAuder, Bits = Net Split ('/') Netmask = Straighten.n Pack ('l', socket inset_tan (netadder)) [0] & amp; ((2L & lt; int; (bits -1) - 1) Return iPad & Netmask == Netmask
Comments
Post a Comment