Search code examples
phplaravellaravel-4laravel-5ip

Grab public IP address using Laravel


My current IP is : 24.62.137.161

and when I use

$ip = $request->getClientIp(); dd($ip);

I keep getting ::1

How can I grab 24.62.137.161 ? I'm not sure if what I'm trying to do if possible.

Any hints / suggestion will be much appreciated.


Solution

  • $ip = trim(shell_exec("dig +short myip.opendns.com @resolver1.opendns.com"));
    

    dd("Public IP: ".$ip); //"Public IP: 24.62.137.161"