Re: How to find callers local IP address?

[email protected] (Aziz Saleh)
Newsgroups php.general
Message-ID <CAPJtNhXbgN30ohFWC3OUiidCJLd8QS=3o3K_UhkA8fSQGUy65g@mail.gmail.com>
You can not access a request's internal IP with PHP. Maybe you can
configure the switch to pass the IP as a parameter in the action URL.

On Sun, Mar 20, 2022 at 6:03 PM Hans Åhlin <[email protected]>
wrote:

> 'SERVER_ADDR'
> The IP address of the server under which the current script is executing.
>
> https://www.php.net/manual/en/reserved.variables.server.php
>
> MvH / Hans Åhlin
>
>
>
> Den sön 20 mars 2022 23:00Hans Åhlin <[email protected]> skrev:
>
>> 'SERVER_ADDR'
>> The IP address of the server under which the current script is executing.
>>
>> https://www.php.net/manual/en/reserved.variables.server.php
>>
>>
>> Den sön 20 mars 2022 08:46Bo Berglund <[email protected]> skrev:
>>
>>> I have a script on my website, which is used to report (by email) state
>>> changes
>>> in home automation power switches.
>>>
>>> It is done by configuring the power switch with an "action URL" to be
>>> hit when a
>>> switch changes state. This works well as far as the switch state
>>> reporting goes.
>>>
>>> But I would like to also get the *internal LAN* IP address of the power
>>> switch
>>> device in my report so I can find it on the network. The IP changes when
>>> I move
>>> it between my locations...
>>>
>>> After googling a bit I have found this code snippet:
>>>
>>> if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
>>>     $ip = $_SERVER['HTTP_CLIENT_IP'];
>>> } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
>>>     $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
>>> } else {
>>>     $ip = $_SERVER['REMOTE_ADDR'];
>>> }
>>>
>>> But when I use it in my reporting I am always getting the external
>>> Internet IP
>>> address of my router instead of the IP of the power switch.
>>>
>>> How can I extract the original device's local LAN IP address from which
>>> the call
>>> was sent?
>>>
>>>
>>> --
>>> Bo Berglund
>>> Developer in Sweden
>>>
>>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.