Search code examples
phphtmlporttraversalnat

How to find out port (nat assigned) from which a connection to a web server is made


Basically I have access to a Apache server and I want to make a NAT traversal application. I have thought about randomly trying ports on both sides but, quickly discarded that idea. I don't have the ability to run my software on the server, or open any ports, but Apache settings could be changed.

Now my question: Is there any way for a web server to detect from which point is incoming connection being sent? I know that the web server must keep it in memory in order to send the generated html to the proper ip and port otherwise the NAT system would break http. But how do I get the port? I am thinking some logging option but I can't find anything usefull. Or perhaps a php function...


Solution

  • Try $_SERVER['REMOTE_PORT'], which'd be the port the user's NAT gateway is connecting from. Similarly, $_SERVER['REMOTE_ADDR'] will the user's gateway's IP.