–
import socket
def get_ipv4():
# 用socket获取本机 IPv4 地址
st = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
st.connect(('10.255.255.255', 1))
ipv4 = st.getsockname()[0]
return ipv4
except Exception:
ipv4 = '127.0.0.1'
finally:
st.close()
# print(ipv4)
return None
–
发表回复