获取电脑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()

 

posted @ 2024-01-23 21:05  liuweipaul123  阅读(7)  评论(0编辑  收藏  举报