-1

I'm using REMOTE_ADDR to fetch ip for use, it's returning to me my company IP: 192.168.30.124 which doesn't match in my maxmind location database and sites like ipstack

However when I go to sites like, they're able to retrieve my public IP which is 103.52.62.220 and the correct country. What am I missing.

Anton
  • 429
  • 4
  • 17
  • You just asked this [here](https://stackoverflow.com/questions/51297966/fetch-public-ip-and-not-private). Is there a reason you deleted and reposted? – user3942918 Jul 12 '18 at 05:57
  • @PaulCrovella I came up some theories how to fix, tried it all and failed that's why I needed to post again. – Anton Jul 12 '18 at 06:16
  • I see. Just a heads up that you could've instead undeleted the original, which is preferable as deleted questions feed into the automatic ban algorithm and might contribute to your account being unable to ask questions in the future. – user3942918 Jul 12 '18 at 06:35
  • I see thanks for the heads up man. – Anton Jul 12 '18 at 06:37

2 Answers2

1

A simple solution presented here by phihag is to do the following:

$externalContent = file_get_contents('http://checkip.dyndns.com/');
preg_match('/Current IP Address: \[?([:.0-9a-fA-F]+)\]?/', $externalContent, $m);
$externalIp = $m[1];

Simply put, you need to get your public IP from a server that would have to route back through that IP address (a server external to your network).

There is more information about this in the link I provided.

  • I tried the same thing using https://api.ipify.org however it threw me to AUS with IP 103.67.235.63 instead of PH ip: 103.52.62.220, Since I'm under a vpn with same possible same network as the servers I might try looking into what Kapsonfire did below. – Anton Jul 12 '18 at 06:22
0

if the server is in the same network, then you'll get only the local ip, because, theres no reason to leave the intranet just to come back. the router routes it directly to the server with the local ip.

this is tcp related

Kapsonfire
  • 1,013
  • 5
  • 17