When I run the following code to determine my device's local IP address, I get 127.0.0.1 instead of 192.168.0.101.
import socket
import threading
PORT = 8080
HOST_NAME = socket.gethostname()
print(HOST_NAME)
SERVER = socket.gethostbyname(HOST_NAME)
print(SERVER)
The output i get on the console is
MyDeviceName.local
127.0.0.1
                127.0.0.1 is localhost address, it is right. If you want your device's address do this:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
print(s.getsockname()[0])
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With