Study/개발 Tip

IP 정보를 가져오는 방법

AC 2023. 2. 10. 01:00
fetch("https://ipinfo.io/json")
  .then(response => response.json())
  .then(data => {
    console.log(data);
  });

 

위 코드를 추가하면 끝

또 다른 방법은 geoip-lite 라는 라이브러리를 사용하면 된다.

const geo = require("geoip-lite");
const ip = "8.8.8.8";
const geoData = geo.lookup(ip);
console.log(geoData);

 

LIST