获取电脑ip
try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 80)) self.ip = s.getsockname()[0] print("ip", self.ip) except: self.ip = "127.0.0.1" finally: s.close()
try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 80)) self.ip = s.getsockname()[0] print("ip", self.ip) except: self.ip = "127.0.0.1" finally: s.close()