Functional schmunctional...

Paul Rubin http
Tue Feb 10 15:50:38 EST 2009


r0g <aioe.org at technicalbloke.com> writes:
> def inet2ip(n):
>   p = (n/16777216)
>   q = ((n-(p*16777216))/65536)
>   r = ((n-((p*16777216)+(q*65536)))/256)
>   s = ((n-((p*16777216)+(q*65536)+(r*256))))
>   return str(p)+"."+str(q)+"."+str(r)+"."+str(s)

from struct import pack
def inet2ip(n):
  xs = pack('L',n)
  return '.'.join(str(ord(x)) for x in xs)



More information about the Python-list mailing list