Being able to access a service to learn your public IP address can be very helpful, but how does the process work? Today’s SuperUser Q&A post has the answer to a curious reader’s question.
Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.
Screenshot courtesy of Douglas Porter (Flickr).
SuperUser reader Harry wants to know what the steps for finding the public IP address of a computer are:
I am aware of services like What Is My IP Address that allows a user to find their public IP address, but what I would like to know is how does such a service get written from scratch? I do not need the code itself, I just want to know the concepts and the steps involved (pseudo code if you will).
This is what I already know about creating such a service:
- I would set up a web application on the Internet that listens to/for port 80.
- When a request comes in, I would examine its source IP address and then package that in a nicely formatted HTML response for the user to see.
Is that it, or is there something else involved here as well?
What are the steps to finding the public IP address of a computer?
SuperUser contributor Scott Chamberlain has the answer for us:
For the most part, what you have listed is all that you need to do for basic functionality.
There is, however, one more thing you could do. You could check the X-Forwarded-For header added by some proxies (the kind used for caching) and/or load balancers and report that address instead because the address you get from the source address will be the proxy’s address, not the user’s.
However, that header is user provided, so there is no way to prove that the address listed in X-Forwarded-For is the real source address of the user.
Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.