[Tutor] print IP address range to stdout
spir
denis.spir at free.fr
Tue Dec 22 19:09:16 CET 2009
MK <lopoff at gmx.net> dixit:
> First function the ip is splitted as i did it. Alright.
> The use 256 as it is the maximum for any digit. ok.
> But what is that ** and exp meaning ????
>
> ----------------------------------------------------------
> def ip_to_int(dotted_ip):
> exp = 3
> intip = 0
> for quad in dotted_ip.split('.'):
> intip = intip + (int(quad) * (256 ** exp))
> exp = exp - 1
> return(intip)
>
> ---------------------------------------------------
As a global explaination, this convert an ip address to a single integer, like if it were a number written in base 256 with 4 digits A,B,C,D:
aaa.bbb.ccc.ddd
--> (A,B,C,D)
--> A*(256^3) + B*(256^2) + C*(256^1) + D * (256^0)
--> n
Denis
________________________________
la vita e estrany
http://spir.wikidot.com/
More information about the Tutor
mailing list