Created
August 10, 2017 07:46
-
-
Save jinuljt/532902ea01e81fa0d7f4c0ac2bb63c24 to your computer and use it in GitHub Desktop.
python snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import socket | |
| def get_local_ip(): | |
| ''' | |
| 获得本机可联网的IP | |
| ''' | |
| sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
| sock.connect(("baidu.com", 80)) | |
| ip = sock.getsockname()[0] | |
| sock.close() | |
| return ip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment