I'm creating a simple TCP server with Python3's socketserver module. I want to get the IP of the server that the server is serving on.
I noticed that there is a server_address
attribute in socketserver (rather, BaseServer), but that returns '0.0.0.0' for the IP. I've also tried using the socket
object and running gethostbyname()
, but python says that the socket object does not have attribute gethostbyname
. Example:
server = socketserver.TCPServer(...)
print(server.server_address) # gives me ('0.0.0.0', [correct port])
print(server.socket.gethostbyname()) # AttributeError
From what I understand, 0.0.0.0 is reserved for "unknown", so the server isn't seeing its IP. Is that correct? What might the solution be?