1

Are there any methods to get my server IP? I am writing a command where I need my server IP as parameter? Tried request_stack but it doesn't work as I expected.

Aipo
  • 1,805
  • 3
  • 23
  • 48
  • Please check Cerads comment on this thread: https://stackoverflow.com/questions/42087613/symfony2-how-to-get-real-server-ip-address – EmilCataranciuc Mar 25 '18 at 12:15

1 Answers1

1

I think you can request an external resource that return your server IP, you can do this with this code in a Symfony command:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'ipinfo.io/ip');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$ip = curl_exec($ch);

I hope this can help you

Jose M. González
  • 12,590
  • 1
  • 13
  • 9