How owner of these websites can show Public IP Address of Visitor?

11/05/2017 22:00

Internet is the global system of interconnected networks and devices (Single or in Group), every device in the network should use (IP Address) to access the internet, and the IP address that used for communication between Internet devices is called (Public IP Address). There is another type of IP Address also that called (Private IP Address) this type is used for Internal networks (Lan networks) for example: if you are using ADSL or any broadband internet at Home, the ISP might give you one Public IP Address to your router, and other user that connected to that router are using private IP Address but all users that connected to that router using one Public IP address that visible to the global network.

In case that the ISP not gave Public IP Address, then, all user that connected to the router using such Public IP address of the ISP company, and usually, because of Public IP Address restriction (Less number available) ISPs will design the network so that thousands of user connected to one Public IP Address.

Now lets answer the questions above: How such website can find or determine your Public IP Address? Simply, when you are typing website address in the browser, like ( and hitting enter, the browser will ask operating system to translate the domain name to IP address this is called DNS translation (DNS stands for Domain Name System that converts URL to IP Address and vice versa), then, once you hit enter, the browser asks operating system to translate the URL you entered to IP Address, and then, your computer Operating system will send GET request to the translated IP address of the domain name.

Now, when Computer sending Get request to IP address, the request of which sent by your computer contains your computer IP Address, and now there are two cases: if you are using Public IP Address, then the request contains your Public IP Address, otherwise, the request contains your Private IP Address. For case 2 if the request contains Private IP Address: it means that you are connected to router that needs to analyze the "REQUEST" to replace your Private IP Address with Public IP Address, and if your router not has any Public IP Address, then another router belongs to ISP will do that, therefore, finally, the request in the final destination should contain Public IP Address of the requester.

Now, we explained that the request contains Public IP address, the remote computer that you are requesting to get information like Google or any other website, can get all information of the request that sent by you! then, it can read your Public IP Address.

Example: The below information is related to (HTTP Request) header that extracted from your request:

Connection: close
From: [email protected]
User-Agent: ia_archiver

PHP Code to Show user IP Address (Public IP Address)

echo "Your IP Address is:".$_SERVER['REMOTE_ADDR'];

PHP Code to show HTTP Request Header:

$headers =  getallheaders(); 
foreach($headers as $key=>$val){ 
  echo $key ': ' $val '<br>'; 

ASP Code to show User IP Address (Public IP Address):

Your IP address is:

Can PHP or ASP Determine Private IP Address?

No. PHP or Any other server-side language or Scripts can't determine your private IP Address because Private IP address is not sent by the request. However, there is such technique using JavaScript WebRTC API that can determine your (Public and Private IP Address) using just client side scripts.