IPGu.net

Developer API

IPGu.net มี API ฟรีสำหรับนักพัฒนา ไม่ต้องลงทะเบียนและไม่ต้อง API key รองรับสองรูปแบบ — plain text สำหรับ script อย่างง่าย และ JSON สำหรับแอปพลิเคชันที่ต้องการข้อมูลเพิ่มเติม

ข้อมูล geolocation ใช้ฐานข้อมูล MaxMind GeoLite2 ซึ่งประมวลผลในเซิร์ฟเวอร์ IPGu.net โดยตรง IP ของคุณไม่ถูกส่งไปยังบุคคลที่สาม

Endpoints ที่มีให้

GET /ip — Plain Text

ส่งคืน IP address สาธารณะของคุณเพียงบรรทัดเดียว ใช้งานง่ายที่สุด เหมาะสำหรับ shell script และ automation

curl https://ipgu.net/ip

ตัวอย่างผลลัพธ์:

203.150.12.45

GET /json — JSON

ส่งคืน IP พร้อมข้อมูล geolocation ในรูปแบบ JSON ประกอบด้วย ประเทศ เมือง ภูมิภาค timezone ISP และหมายเลข ASN

curl https://ipgu.net/json

ตัวอย่างผลลัพธ์:

{
  "ip": "203.150.12.45",
  "country_code": "TH",
  "country": "Thailand",
  "region": "Bangkok",
  "city": "Bangkok",
  "timezone": "Asia/Bangkok",
  "asn": "AS7470",
  "isp": "True Internet Co., Ltd."
}

ฟิลด์ที่ไม่มีข้อมูลจะไม่แสดงในผลลัพธ์ ค่า asn อยู่ในรูปแบบ AS + หมายเลข เช่น AS7470

ตัวอย่างการใช้งาน

Shell / Bash

# เก็บ IP ในตัวแปร
MY_IP=$(curl -s https://ipgu.net/ip)
echo "IP ของคุณ: $MY_IP"

# ดึงข้อมูล JSON แล้วกรองด้วย jq
curl -s https://ipgu.net/json | jq '.country'

JavaScript (Fetch API)

// ดึง IP เป็น plain text
const ip = await fetch('https://ipgu.net/ip').then(r => r.text());
console.log('IP:', ip.trim());

// ดึงข้อมูล JSON
const data = await fetch('https://ipgu.net/json').then(r => r.json());
console.log(data.country, data.city);

Python

import requests

# Plain text
ip = requests.get('https://ipgu.net/ip').text.strip()
print('IP:', ip)

# JSON
data = requests.get('https://ipgu.net/json').json()
print(data['country'], data.get('city', ''))

นโยบายการใช้งาน (Fair Use)

API นี้ให้บริการฟรีโดยไม่มีการยืนยันตัวตน เพื่อให้บริการนี้ยังคงใช้งานได้ต่อไปสำหรับทุกคน กรุณาใช้งานอย่างสมเหตุสมผล อย่า scrape หรือ poll ถี่เกินความจำเป็น หากต้องการใช้งานในระดับสูง ควรพิจารณา MaxMind GeoIP2 โดยตรง

ทั้งสอง endpoint ส่ง header Access-Control-Allow-Origin: * ทำให้ใช้งานได้จาก JavaScript ในเบราว์เซอร์โดยตรง (CORS-enabled)

ข้อมูลเพิ่มเติม

สำหรับข้อมูลว่า geolocation ทำงานอย่างไรและข้อจำกัดที่ควรรู้ ดูได้ที่ IP คืออะไร? สำหรับคำสั่ง curl และ terminal เพิ่มเติม ดูได้ที่ คำสั่ง CLI