diff --git a/routes_discovery.py b/routes_discovery.py index 95e7eae..a31c055 100644 --- a/routes_discovery.py +++ b/routes_discovery.py @@ -71,13 +71,10 @@ def _get_listening_ports(): port = int(port_match.group(1)) pid_match = re.search(r'pid=(\d+)', line) - if not pid_match: - continue - pid = int(pid_match.group(1)) + pid = int(pid_match.group(1)) if pid_match else None - # 提取进程名 proc_match = re.search(r'users:\(\(\"([^\"]+)\"', line) - proc_name = proc_match.group(1) if proc_match else 'unknown' + proc_name = proc_match.group(1) if proc_match else '未知进程' services.append({ 'port': port, @@ -219,10 +216,16 @@ def register_discovery_routes(app): continue seen_ports.add(port) - cmdline = _get_process_cmdline(pid) - cwd = _get_process_cwd(pid) - name = _guess_service_name(pid, svc['process'], cmdline) - svc_type = _guess_service_type(cmdline) + if pid: + cmdline = _get_process_cmdline(pid) + cwd = _get_process_cwd(pid) + name = _guess_service_name(pid, svc['process'], cmdline) + svc_type = _guess_service_type(cmdline) + else: + cmdline = '' + cwd = '' + name = svc['process'] + svc_type = 'unknown' undiscovered.append({ 'port': port, diff --git a/templates_full.txt b/templates_full.txt index 3f780eb..675dd04 100644 --- a/templates_full.txt +++ b/templates_full.txt @@ -2905,7 +2905,7 @@
:${s.port} ${s.suggested_name} - PID ${s.pid} + PID ${s.pid != null ? s.pid : '受权限限制'}