首先第一步定义配置
const dns = require('dns'); const net = require('net'); const validOptions = [ { "name": "ports", "cmd": ["-p", "--ports"], "value": "1-10,80", "min": 1, "max": 65535, "type": "range", "description": "The port or range of ports to scan (e.g. '80', '1-1024', '80,443'). Default: '1-65535'.", "description_zh": "要扫描的端口或端口范围(例如:'80','1-1024','80,443')。默认值:'1-65535'。" }, { "name": "timeout", "cmd": ["-t", "--timeout"], "value": 10000, "type": "number", "description": "The timeout for each port scan, in milliseconds. Default: 10000.", "description_zh": "每个端口扫描的超时时间(毫秒)。默认值:10000。" }, { "name": "maxQueueSize", "cmd": ["-q", "--max-queue-size"], "value": 100, "type": "number", "description": "The maximum size of the scan queue. Default: 100.", "description_zh": "扫描队列的最大大小。默认值:100。" }, { "name": "showAll", "cmd": ["-a", "--show-all"], "value": false, "type": "bool", "description": "Show all ports, including closed and timed out ports.", "description_zh": "显示全部端口,包含关闭和超时的端口。" }, { "name": "help", "cmd": ["-h", "--help"], "value": false, "type": "bool", "description": "Show usage information.", "description_zh": "显示使用说明。" } ];
然后看第二部分代码