✨ mac端口快捷选择
This commit is contained in:
parent
ef1b8c186e
commit
0fdfe4d169
@ -12,7 +12,7 @@ type LocalPort = {
|
|||||||
export const initLocalApi = () => {
|
export const initLocalApi = () => {
|
||||||
const command = process.platform === 'win32'
|
const command = process.platform === 'win32'
|
||||||
? 'netstat -a -n'
|
? 'netstat -a -n'
|
||||||
: 'netstat -tuln';
|
: 'netstat -an | grep LISTEN\n';
|
||||||
|
|
||||||
ipcMain.on("local.getLocalPorts", async (event, args) => {
|
ipcMain.on("local.getLocalPorts", async (event, args) => {
|
||||||
log.info("开始获取本地端口")
|
log.info("开始获取本地端口")
|
||||||
@ -30,6 +30,8 @@ export const initLocalApi = () => {
|
|||||||
log.debug(`sc ${stdout}`)
|
log.debug(`sc ${stdout}`)
|
||||||
let ports = [];
|
let ports = [];
|
||||||
if (stdout) {
|
if (stdout) {
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
// window
|
||||||
ports = stdout.split('\r\n')
|
ports = stdout.split('\r\n')
|
||||||
.filter(f => f.indexOf('TCP') > 0 || f.indexOf('UDP') > 0)
|
.filter(f => f.indexOf('TCP') > 0 || f.indexOf('UDP') > 0)
|
||||||
.map(m => {
|
.map(m => {
|
||||||
@ -58,6 +60,34 @@ export const initLocalApi = () => {
|
|||||||
|
|
||||||
return singe;
|
return singe;
|
||||||
})
|
})
|
||||||
|
} else if (process.platform === 'darwin') {
|
||||||
|
// mac
|
||||||
|
ports = stdout.split('\n')
|
||||||
|
.filter(m => {
|
||||||
|
const cols = m.split(' ')
|
||||||
|
.filter(f => f != '')
|
||||||
|
const local = cols[3]
|
||||||
|
return local
|
||||||
|
})
|
||||||
|
.map(m => {
|
||||||
|
const cols = m.split(' ')
|
||||||
|
.filter(f => f != '')
|
||||||
|
const local = cols[3]
|
||||||
|
console.log(local, '1')
|
||||||
|
const s = local.lastIndexOf(".")
|
||||||
|
let localIP = local.slice(0, s);
|
||||||
|
let localPort = local.slice(s - local.length + 1);
|
||||||
|
const singe: LocalPort = {
|
||||||
|
protocol: cols[0],
|
||||||
|
ip: localIP,
|
||||||
|
port: localPort
|
||||||
|
}
|
||||||
|
return singe;
|
||||||
|
})
|
||||||
|
// .filter(f => f.indexOf('TCP') > 0 || f.indexOf('UDP') > 0)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ports.sort((a, b) => a.port - b.port);
|
ports.sort((a, b) => a.port - b.port);
|
||||||
|
Loading…
Reference in New Issue
Block a user