From 09921d984a65c994539d11f9a717a40528b6bdab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=90=E6=AE=87?= Date: Fri, 29 Nov 2024 23:13:30 +0800 Subject: [PATCH] add more sniff settings --- src/main/utils/template.ts | 19 +++- src/renderer/src/pages/sniffer.tsx | 135 ++++++++++++++++------------- src/shared/types.d.ts | 2 + 3 files changed, 91 insertions(+), 65 deletions(-) diff --git a/src/main/utils/template.ts b/src/main/utils/template.ts index e2a0341d..6bc35132 100644 --- a/src/main/utils/template.ts +++ b/src/main/utils/template.ts @@ -90,12 +90,23 @@ export const defaultControledMihomoConfig: Partial = { }, TLS: { ports: [443] - }, - QUIC: { - ports: [443] } }, - 'skip-domain': ['+.push.apple.com'] + 'skip-domain': ['+.push.apple.com'], + 'skip-dst-address': [ + '91.105.192.0/23', + '91.108.4.0/22', + '91.108.8.0/21', + '91.108.16.0/21', + '91.108.56.0/22', + '95.161.64.0/20', + '149.154.160.0/20', + '185.76.151.0/24', + '2001:67c:4e8::/48', + '2001:b28:f23c::/47', + '2001:b28:f23f::/48', + '2a0a:f280:203::/48' + ] }, profile: { 'store-selected': true, diff --git a/src/renderer/src/pages/sniffer.tsx b/src/renderer/src/pages/sniffer.tsx index 646f3a4e..e6f01d85 100644 --- a/src/renderer/src/pages/sniffer.tsx +++ b/src/renderer/src/pages/sniffer.tsx @@ -4,7 +4,7 @@ import SettingCard from '@renderer/components/base/base-setting-card' import SettingItem from '@renderer/components/base/base-setting-item' import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config' import { restartCore } from '@renderer/utils/ipc' -import React, { useState } from 'react' +import React, { ReactNode, useState } from 'react' import { MdDeleteForever } from 'react-icons/md' const Sniffer: React.FC = () => { @@ -17,10 +17,25 @@ const Sniffer: React.FC = () => { sniff = { HTTP: { ports: [80, 443], 'override-destination': false }, TLS: { ports: [443] }, - QUIC: { ports: [443] } + QUIC: { ports: [] } }, 'skip-domain': skipDomain = ['+.push.apple.com'], - 'force-domain': forceDomain = [] + 'force-domain': forceDomain = [], + 'skip-dst-address': skipDstAddress = [ + '91.105.192.0/23', + '91.108.4.0/22', + '91.108.8.0/21', + '91.108.16.0/21', + '91.108.56.0/22', + '95.161.64.0/20', + '149.154.160.0/20', + '185.76.151.0/24', + '2001:67c:4e8::/48', + '2001:b28:f23c::/47', + '2001:b28:f23f::/48', + '2a0a:f280:203::/48' + ], + 'skip-src-address': skipSrcAddress = [] } = sniffer || {} const [changed, setChanged] = useState(false) const [values, originSetValues] = useState({ @@ -29,7 +44,9 @@ const Sniffer: React.FC = () => { overrideDestination, sniff, skipDomain, - forceDomain + forceDomain, + skipDstAddress, + skipSrcAddress }) const setValues = (v: typeof values): void => { originSetValues(v) @@ -58,20 +75,45 @@ const Sniffer: React.FC = () => { } }) } - const handleDomainChange = (type: string, value: string, index: number): void => { - const newDomains = [...values[type]] - if (index === newDomains.length) { - if (value.trim() !== '') { - newDomains.push(value) - } - } else { - if (value.trim() === '') { - newDomains.splice(index, 1) + const handleListChange = (type: string, value: string, index: number): void => { + const list = [...values[type]] + if (value.trim()) { + if (index < list.length) { + list[index] = value } else { - newDomains[index] = value + list.push(value) } + } else { + list.splice(index, 1) } - setValues({ ...values, [type]: newDomains }) + setValues({ ...values, [type]: list }) + } + const renderListInputs = (type: string, placeholder: string): ReactNode => { + const currentItems = values[type] + const showNewLine = currentItems.every((item: string) => item.trim() !== '') + + return [...currentItems, ...(showNewLine ? [''] : [])].map((item, index) => ( +
+ handleListChange(type, v, index)} + /> + {index < values[type].length && ( + + )} +
+ )) } return ( @@ -144,6 +186,7 @@ const Sniffer: React.FC = () => { handleSniffPortChange('HTTP', v)} /> @@ -152,6 +195,7 @@ const Sniffer: React.FC = () => { handleSniffPortChange('TLS', v)} /> @@ -160,60 +204,29 @@ const Sniffer: React.FC = () => { handleSniffPortChange('QUIC', v)} />
-

跳过嗅探域名

- {[...values.skipDomain, ''].map((d, index) => ( -
- handleDomainChange('skipDomain', v, index)} - /> - {index < values.skipDomain.length && ( - - )} -
- ))} +

跳过域名嗅探

+ {renderListInputs('skipDomain', '例:+.push.apple.com')} +
+ +
+

强制域名嗅探

+ {renderListInputs('forceDomain', '例:v2ex.com')} +
+ +
+

跳过目标地址嗅探

+ {renderListInputs('skipDstAddress', '例:1.1.1.1/32')}
-

强制嗅探域名

- {[...values.forceDomain, ''].map((d, index) => ( -
- handleDomainChange('forceDomain', v, index)} - /> - {index < values.forceDomain.length && ( - - )} -
- ))} +

跳过来源地址嗅探

+ {renderListInputs('skipSrcAddress', '例:192.168.1.1/24')}
diff --git a/src/shared/types.d.ts b/src/shared/types.d.ts index 08f8aed0..3f80cf7d 100644 --- a/src/shared/types.d.ts +++ b/src/shared/types.d.ts @@ -352,6 +352,8 @@ interface IMihomoSnifferConfig { 'force-dns-mapping'?: boolean 'force-domain'?: string[] 'skip-domain'?: string[] + 'skip-dst-address'?: string[] + 'skip-src-address'?: string[] sniff?: { HTTP?: { ports: (number | string)[]