22 lines
991 B
Python
22 lines
991 B
Python
|
|
import socket
|
||
|
|
import psutil
|
||
|
|
from midware.config.base_config import DEVICE_CONFIG_DICT, UDP_CONFIG
|
||
|
|
|
||
|
|
def check_port_listen(ip, port):
|
||
|
|
"""检测指定IP:端口是否被监听"""
|
||
|
|
for conn in psutil.net_connections(kind='inet'):
|
||
|
|
if conn.laddr.ip == ip and conn.laddr.port == port and conn.status == 'LISTEN':
|
||
|
|
return True
|
||
|
|
return False
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
local_ip = UDP_CONFIG["LOCAL_IP"]
|
||
|
|
# 检测所有外设UDP端口
|
||
|
|
print("===== UDP端口监听状态检测 =====")
|
||
|
|
for dev_name, dev_info in DEVICE_CONFIG_DICT.items():
|
||
|
|
port = dev_info["udp_port"]
|
||
|
|
is_listen = check_port_listen(local_ip, port)
|
||
|
|
status = "✅ 正常监听" if is_listen else "❌ 未监听"
|
||
|
|
print(f"{dev_name} | {local_ip}:{port} | {status}")
|
||
|
|
# 检测故障注入软件对接端口(非监听,为发送套接字)
|
||
|
|
print(f"\n故障注入软件接收端口:{local_ip}:{UDP_CONFIG['FAULT_INJECT_PORT']}(自测客户端监听)")
|