ip address and network

Mike C. Fletcher mcfletch at rogers.com
Thu Oct 23 10:47:33 EDT 2003


You could use something like:
    import struct,socket
    struct.unpack( '>I', socket.inet_aton( '193.108.240.17' ))[0]

to get the IP addresses as Python long integers, then do something like:

    (addr & (~mask)) == (network & (~mask))

There's more efficient ways I'm sure, but I don't have time to play too 
much today :) . 

Have fun,
Mike

Ruslan Spivak wrote:
...

> i have ip address(a lot of different ip addresses) and i need to 
> determine if it belongs to some network. (for example ip - 
> 193.108.240.17, network 193.108.240.0/22).
> How can i solve this?

...

_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/








More information about the Python-list mailing list