2021-07-06
CSR (Client side rendering) でユーザの public ip を取得する方法です。
ipify を使う
ipify - A Simple Public IP Address API
https://www.ipify.org/const API_URL = 'https://api.ipify.org/?format=json'
const res = await fetch(API_URL)
const data = await res.json()
console.log(data.ip)
ReactHooks の例
Code:
tools/global-ip.tsx at master · elzup/tools
https://github.com/elzup/tools/blob/master/src/pages/global-ip.tsxDemo:
public IP 取得
https://tools.anozon.me/global-ip