개발/Node.js
Typescript 현재 접속한 사용자의 아이피 가져오기
다물칸
2023. 8. 19. 13:41
728x90
반응형
https://geolocation-db.com/json/ 사이트 정보를 이용하는 방법을 사용합니다.
이 방법은 인터넷 외부 아이피를 가져오기 때문에 내부 아이피는 가져올 수는 없습니다.
외부 아이피를 통해 접속한 사용자들은 모두 같은 아이피로 처리되요.
const result = axios.get('https://geolocation-db.com/json/').then(async (res) => {
console.log("Country_code = " + res.data.country_code);
console.log("Country_Name = " + res.data.country_name);
console.log("State = " + res.data.state)
console.log("City = " + res.data.city);
console.log("Latitude = " + res.data.latitude)
console.log("Longitude = " + res.data.longitude)
console.log("postal = " + res.data.postal)
console.log("IPv4 = " + res.data.IPv4)
// 이 안에서 사용자 최종 로그인일자 및 아이피 업데이트
await prisma.tuser.update({
data: {
lastlogingat: new Date(),
lastloginip: res.data.IPv4 || ""
},
where: {
userkey: checkId.userkey
}
})
}반응형