DEV Community

Discussion on: Get IP Clients Addresses

Collapse
 
adithyapaib profile image
adithyapaib

how to make an api like these sites ?

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

Collapse
 
jenueldev profile image
Jenuel Oras Ganawed

Hi! thank you for showing interest in this post. The idea here is to fetch data from a backend server using a link provided by the backend.. If you would like to create something like this you can start learning how Rest Api works..

Collapse
 
adithyapaib profile image
adithyapaib

Hey
I actually made several rest API's (nodejs) but I could find proper source or information to make an API to get IP address without 3rd part api's. Is there any proper resource to do it? Or can you write a post on that would love to read it .
Thank you

Thread Thread
 
jenueldev profile image
Jenuel Oras Ganawed

I think for js you have to use libraries to do it... If you have tried python I think its easier in python language.... but anyway, Ill try to search about it and make a post about it also :)

Thread Thread
 
adithyapaib profile image
adithyapaib

Thanks man really appreciate it