feat(sub): generate random IPs from CIDR host addresses (#6784)

Operators who front a server with an IP range (a CDN or anycast prefix) had to
list each address as its own host. A host address may now be a CIDR, and every
subscription fetch expands it into up to randomCount (1–100, default 1) unique
random host IPs from the range, IPv4 and IPv6 alike, skipping the network and
broadcast addresses. The panel's own previews, QR codes and tunnel config
exports (WireGuard, AmneziaWG, TUIC, MTProto) expand it the same way, and the
externalProxy importer writes the model's default count so the re-sync still
recognises untouched imported hosts.
This commit is contained in:
Pejman Yousefi
2026-10-24 06:43:44 +03:30
committed by GitHub
parent f6a233220a
commit 40cea0c2fe
33 changed files with 886 additions and 8 deletions
@@ -74,6 +74,7 @@ function defaultsFor(host: HostRecord | null): FormShape {
mihomoIpVersion: host?.mihomoIpVersion as BulkAddHostValues['mihomoIpVersion'],
mihomoX25519: host?.mihomoX25519 ?? false,
shuffleHost: host?.shuffleHost ?? false,
randomCount: host?.randomCount ?? 1,
};
}
@@ -95,6 +96,8 @@ export default function HostFormModal({
const security = (useWatch({ control: methods.control, name: 'security' }) ?? 'same') as string;
const showTls = security === 'tls' || security === 'reality' || security === 'same';
const showTlsExtras = security === 'tls' || security === 'same';
const watchedHosts = useWatch({ control: methods.control, name: 'hosts' });
const hasCidr = Boolean(watchedHosts?.some((h) => typeof h === 'string' && h.includes('/')));
// React resets this during render rather than in an effect so the modal's
// first open frame already shows cleared fields.
@@ -255,6 +258,11 @@ export default function HostFormModal({
placeholder="cdn.example.com, cdn2.example.com:443"
/>
</FormField>
{hasCidr && (
<FormField name="randomCount" label={t('pages.hosts.fields.randomCount')}>
<InputNumber min={1} max={100} style={{ width: '100%' }} />
</FormField>
)}
<FormField
name="port"
label={t('pages.hosts.fields.port')}