I am trying to run a python server on a Raspberry Pi, and I need the local IP address of it to connect. I realize I can just type ifconfig and get my IP address, but I would really like to be able to get it from the python script. I have tried socket.gethostbyname(socket.getfqdn()), but that seems to only work on Windows. When I run it on my raspberry pi, it seems to always return 127.0.1.1. Does anyone know a command that will get the local IP address on linux?
Add a comment
|
2 Answers
You can use an external package, for example netifaces, or you can look for the ipaddress of a given interface, specified by its name. Take a look at this question.