Reputation: 391
How can Websites find and display your IP? For example, on whatismyip.org, at the top, it will show you 'Your IP is: x.x.x.x'. How does the website do this? I understand it has to do with client-server communication, but I'm not sure how to communicate with the server from the html. What library or language can I use to do this?
Upvotes: 0
Views: 121
Reputation: 1251
HTML is just a language purely built for use to display formatted text to your browser which operates inside the client side. It has no capability on grabbing information like IP address. Only the server side can grab your IP because how the web browsing works, when you connect to a specific domain or web address, it connects your browser to the server which your browser (the client) gives details like IP and your browser's client name (like Chrome/Safari/Firefox) and so the server has now the information like IP address. In order to display that, you can either use scripting languages common in web programming like PHP/Python/PERL.
Upvotes: 0
Reputation: 522522
It's not "HTML" doing it, it's the server that is serving the HTML doing it. To respond to your computer with a website, the server needs to know your IP, which it gets from a TCP/IP handshake. The server simply outputs this IP into an HTML page.
Sample PHP script:
<html>
...
Your IP: <?php echo $_SERVER['REMOTE_ADDR']; ?>
...
</html>
Upvotes: 2