IP Math anyone?
Erno Kuusela
erno-news at erno.iki.fi
Mon Feb 26 16:23:39 EST 2001
In article <mailman.983221028.6007.python-list at python.org>, Timothy
Grant <tjg at exceptionalminds.com> writes:
| Hi all,
| I checked Parnassus, but couldn't find anything, so I'll ask
| here. Has anyone done anything with IP math (e.g.,
| 192.168.0.254 + 1 = 192.168.1.1).
assuming you actually mean 192.168.0.254 + 1 = 192.168.0.255,
try something like...
>>> def dotted2int(ds):
... return struct.unpack('!I', socket.inet_aton(ds))[0]
...
>>> def int2dotted(i):
... return socket.inet_ntoa(struct.pack('!I', i))
...
>>> print int2dotted(dotted2int('192.168.0.254') + 1)
192.168.0.255
-- erno
More information about the Python-list
mailing list