How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
If you don't want to use external packages and don't want to rely on outside Internet servers, this might help. It's a code sample that I found on Google Code Search and modified to return required information:
Usage:
As it relies on
windll
, this will work only on Windows.A version I do not believe that has been posted yet. I tested with python 2.7 on Ubuntu 12.04.
Found this solution at : http://code.activestate.com/recipes/439094-get-the-ip-address-associated-with-a-network-inter/
Example Result:
On Linux:
To get the ip address you can use a shell command directly in python:
I just found this but it seems a bit hackish, however they say tried it on *nix and I did on windows and it worked.
This assumes you have an internet access, and that there is no local proxy.