```python import socket import time def check_network_status(host="www.baidu.com", port=80, timeout=3): try: socket.setdefaulttimeout(timeout) socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port)) return True except Exception as ex: print("网络连接异常:", ex) return False if __name__ == "__main__": while True: if check_network_status(): print("网络状态正常") else: print("网络状态异常") time.sleep(5) ``` [2024-06-21 17:51:41 | AI写代码神器 | 159点数解答]