From 62d08096b36289eb6a33b0bca7cf470f0490623a Mon Sep 17 00:00:00 2001 From: RTAkland Date: Tue, 21 Dec 2021 20:54:38 +0800 Subject: [PATCH] feat: added get_host_ip.py --- lib/get_host_ip.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/get_host_ip.py b/lib/get_host_ip.py index b32fcd1..1918515 100644 --- a/lib/get_host_ip.py +++ b/lib/get_host_ip.py @@ -2,4 +2,19 @@ # @Author: markushammered@gmail.com # @Development Tool: PyCharm # @Create Time: 2021/12/21 -# @File Name: get_host_ip.py \ No newline at end of file +# @File Name: get_host_ip.py + +import socket + + +def get_host_ip(): + """ + 查询本机ip地址 + :return: ip + """ + ip_s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + ip_s.connect(('8.8.8.8', 80)) + ip = ip_s.getsockname()[0] + ip_s.close() + + return ip \ No newline at end of file