I'm having PHP and Python scripts running on different machines, and I want to get the IP of the machine from these scripts.
It seems like it's directing me to the loopback device and not to the network card whenever I try this from within the machine (which is where these scripts are located).
When I called PHP script that only runs phpinfo();
from the browser I had the wanted result but when I used curl it gave me the loopback address.
I tried multiple ways that should work
in Python:
socket.gethostbyname(socket.gethostname())
in PHP:
$_SERVER['HTTP_HOST']
or getHostByName(php_uname('n'));
The bash command hostname -I
, is working for me since it's ignoring the loopback address. I wanted to know if there's something like this built-in PHP/Python.
Otherwise, I think my solution would be to just call this bash command from these scripts.