KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
at the moment I do: def get_inet_ip(): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(('mysite.com', 80)) return s.getsockname()[0] This was based on: Finding local IP addresses using Python's stdlib However, This looks a bit dubious. As far as I can tell, it opens a socket to mysite.com:80, and then returns the first address for that socket, assuming it to be an IPv4 address. This seems a bit dodgy... i dont think we can ever guaranteee that to be the case. Thats my first question, is it safe? On an IPv6-enable server, could the IPv6 address ever be returned unexpectedly? My second question, is how do I get the IPv6 address in a similar way. Im going to modify the function to take an optional ipv6 paramater.
Tags (comma-separated)
Save Edits
Cancel