I am building a solution in php which requires me to accurately know the ip of the requestor. For most cases, the classic call to
$ip = $_SERVER['REMOTE_HOST'];
works just fine.
However, I've noted that in the case where the client is making their request over a tethered connection, I get a completely different address than what google and my firewall report.
I can verify this on the client (tethered) side by searching for "my ip" on google which gives me an IP that matches what my server's firewall is reporting as well. Neither of these match what the $_SERVER['REMOTE_HOST']
contains on the server side though.
My questions then are:
- Why do these addresses differ in general?
- How do I get to the ip address that my firewall and google see, specifically using php?
Huh, turns out this was being done using a javascript "feature" (what I'd think about calling a vulnerability instead) all along. Scary stuff, as it also exposes your internal IP address as well. Anyway it's something called WebRTC, that just started getting a lot of attention this week as it's been officially implemented by firefox and chrome:
Source: https://github.com/diafygi/webrtc-ips
Demo: https://diafygi.github.io/webrtc-ips/