Saturday, June 25, 2011

Ip address to location

Дэлхийн улс бүхэн өөрийн гэсэн ip address-тэй. Харин хайлтын явцад CSV файлаар ip number гэж нэрлэгдэх тоо олддог юм байна.

"begin_ip","end_ip","begin_num","end_num","country","name" "61.88.0.0","61.91.255.255","1029177344","1029439487","AU","Australia" "61.92.0.0","61.93.255.255","1029439488","1029570559","HK","Hong Kong" "61.94.0.0","61.94.7.255","1029570560","1029572607","ID","Indonesia"

ip address нь тоо руу шилжих дүрмийг бичвэл:

ipnum = 16777216*w + 65536*x + 256*y + z (1)

where IP Address = w.x.y.z

The reverse of this formula is
w = int ( ipnum / 16777216 ) % 256;
x = int ( ipnum / 65536 ) % 256;
y = int ( ipnum / 256 ) % 256;
z = int ( ipnum ) % 256;
Where % is the mod operator.

No comments: