snipplrCallback({"id":14807,"title":"convert-ip-to-int-and-int-to-ip","source":"
def<\/span> IntToDottedIP(<\/span> intip )<\/span>:<\/div><\/li> octet =<\/span> ''<\/span><\/div><\/li> for<\/span> exp in<\/span> [<\/span>3<\/span>,<\/span>2<\/span>,<\/span>1<\/span>,<\/span>0<\/span>]<\/span>:<\/div><\/li> octet =<\/span> octet + str<\/span>(<\/span>intip \/ (<\/span> 256<\/span> ** exp )<\/span>)<\/span> + "."<\/span><\/div><\/li> intip =<\/span> intip % (<\/span> 256<\/span> ** exp )<\/span><\/div><\/li> return<\/span>(<\/span>octet.rstrip<\/span>(<\/span>'.'<\/span>)<\/span>)<\/span><\/div><\/li> <\/div><\/li> def<\/span> DottedIPToInt(<\/span> dotted_ip )<\/span>:<\/div><\/li> exp =<\/span> 3<\/span><\/div><\/li> intip =<\/span> 0<\/span><\/div><\/li> for<\/span> quad in<\/span> dotted_ip.split<\/span>(<\/span>'.'<\/span>)<\/span>:<\/div><\/li> intip =<\/span> intip + (<\/span>int<\/span>(<\/span>quad)<\/span> * (<\/span>256<\/span> ** exp)<\/span>)<\/span><\/div><\/li> exp =<\/span> exp - 1<\/span><\/div><\/li> return<\/span>(<\/span>intip)<\/span><\/div><\/li><\/ol><\/pre>","link":"https:\/\/snipplr.com\/view\/14807\/convert-ip-to-int-and-int-to-ip"});