# -*- encoding: utf-8 -*-
import socket
def getip():
"""
获取本机IP
:return:
"""
try:
csock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
csock.connect(('119.29.29.29', 53))
(addr, port) = csock.getsockname()
csock.close()
return addr
except Exception as e:
print(e)
return False
if __name__ == "__main__":
status = getip()
if status:
print("IP获取成功")
print("当前IP: ", status)
else:
print("IP获取失败")