Every request for a webpage has a list of 'Server Variables' that is passed with the Page name request.. (Basic HTML Stuff)

REMOTE_ADDR will contain the IP of the Remote system requesting the page, and in the case of a Proxy Server we use
HTTP_X_FORWARDED_FOR which will contain the originating IP address, and if the request was Via multiple Proxy's we take the last IP in there...

see this wiki for more