This commit is contained in:
condor
2026-07-24 18:54:53 +08:00
parent 43c2a411b9
commit 679e0b4184
128 changed files with 13855 additions and 1 deletions
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env python
import socket
def Get_local_ip():
"""
Returns the actual ip of the local machine.
This code figures out what source address would be used if some traffic
were to be sent out to some well known address on the Internet. In this
case, a Google DNS server is used, but the specific address does not
matter much. No traffic is actually sent.
"""
try:
socket.setdefaulttimeout(5)
csock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
csock.connect(('1.1.1.1', 80))
(addr, port) = csock.getsockname()
csock.close()
return addr
except socket.error:
return "127.0.0.1"
if __name__ == "__main__":
IPADDR = Get_local_ip()
print(IPADDR)