DEV Community

Discussion on: Get IP Clients Addresses

Collapse
 
deaddoctor profile image
deaddoctor • Edited

just look for X-Forwarded-For in your request header.
if you're using express.js something like this should work:

app.get('/get/ip', function (req, res) {
    const ipAddress =  req.headers['x-forwarded-for']?.split(',').shift() || req.socket?.remoteAddress
    res.send(ipAddress);
})
Enter fullscreen mode Exit fullscreen mode
Collapse
 
adithyapaib profile image
adithyapaib

So if I make a http request to the end I will get the public IP address?

Thread Thread
 
deaddoctor profile image
deaddoctor

yes, it's show you the IP address of a client connecting to your web server (which in your case is Express.js)
developer.mozilla.org/en-US/docs/W...

Thread Thread
 
adithyapaib profile image
adithyapaib

Will try it out
Thank you so much 🥰❤️

Collapse
 
adithyapaib profile image
adithyapaib • Edited

get-ip-eight.vercel.app/ working thanks
anyway to get ip location without third party api