How to get the client IP using a Symfony 4 application hosted on Azure Web App

I want to log every login attempts on a Web App (Symfony 4.1) hosted on Azure.

Based on this question, to get the client IP, I’m using :

// $requestStack being SymfonyComponentHttpFoundationRequestStack
$ip = $this->requestStack->getMasterRequest()->getClientIp();

However, the logs tell :

[2020-03-10 10:55:56] login_attempt.INFO: User ‘username’ successfully logged in from ip ‘172.16.1.1’ [] []

As you can notice, this is a private IP. I tried to log in from differents connections, but I’m always getting that IP, 172.16.1.1. Where does this IP come from and how to get the real public IP of the client ?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *