酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

写一段python网络状态监测代码

```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点数解答]

相关提问