From 79f48ca22b369a005bd7d2216661bece7ba4335c Mon Sep 17 00:00:00 2001 From: luckjiawei <8473136@qq.com> Date: Sun, 11 Aug 2024 18:52:41 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E4=BF=AE=E5=A4=8Dlinux=E6=89=AB?= =?UTF-8?q?=E6=8F=8F=E6=9C=AC=E5=9C=B0=E7=AB=AF=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/api/local.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/electron/api/local.ts b/electron/api/local.ts index 216490c..fbd9fab 100644 --- a/electron/api/local.ts +++ b/electron/api/local.ts @@ -12,7 +12,7 @@ type LocalPort = { export const initLocalApi = () => { const command = process.platform === 'win32' ? 'netstat -a -n' - : 'netstat -an | grep LISTEN\n'; + : 'netstat -an | grep LISTEN'; ipcMain.on("local.getLocalPorts", async (event, args) => { log.info("开始获取本地端口") @@ -86,6 +86,28 @@ export const initLocalApi = () => { }) // .filter(f => f.indexOf('TCP') > 0 || f.indexOf('UDP') > 0) + } else if (process.platform === 'linux') { + ports = stdout.split('\n') + .filter(f => + f.indexOf('tcp') !== -1|| + f.indexOf('tcp6') !== -1|| + f.indexOf('udp') !== -1 || + f.indexOf('udp6') !== -1 + ).map(m => { + const cols = m.split(' ') + .filter(f => f != '') + const local = cols[3] + const s = local.lastIndexOf(":") + let localIP = local.slice(0, s); + let localPort = local.slice(s - local.length + 1); + console.log(1) + const singe: LocalPort = { + protocol: cols[0], + ip: localIP, + port: localPort + } + return singe; + }) } }