node

ip to country

ไปเจอ database ว่า ip นั้นขอประเทศไหนก็เลยจดไว้

http://ip-to-country.webhosting.info/downloads/ip-to-country.csv.zip

ก็ import ลง db ซะ ข้อมูลข้างในจะเป็น range ของ ip นั้นเริ่มและสุดที่ไหน
วิธีการก็เอา ip ของเราไป convert dot address to network address (inet_aton) ก่อน
หลักการคือ ถ้า
ip = a.b.c.d
ก็จะเป็น
(a*256*256*256) + (b*256*256) + (c*256) + d;

หรือใช้ function INET_ATON ของ MySQL ก็มีอยู่แล้ว

ปล. รูปธงประเทศเอาจาก famfamfam ก็ได้
เพราะชื่อไฟล์เขารันตาม ISO 3166-1 alpha-2 country codes

Comments

คนแปลกหน้า's picture

ที่จริงตอ

ที่จริงตอนคำนวณ ใช้ ip2long() ก็ได้นะครับ ผลลัพท์ออกมาเหมือนกันครับ

คนแปลกหน้า's picture

nice blog cobro

nice blog
cobro

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.