MCPcopy Create free account
hub / github.com/SamNet-dev/snix / newScanAllCmd

Function newScanAllCmd

cmd/snix/scan.go:184–282  ·  view source on GitHub ↗
(g *globalFlags)

Source from the content-addressed store, hash-verified

182}
183
184func newScanAllCmd(g *globalFlags) *cobra.Command {
185 var sniTarget string
186 cmd := &cobra.Command{
187 Use: "all",
188 Short: "Run IP and SNI scans together and emit a suggested profile",
189 Long: `Runs both scans and emits a ready-to-paste sni_pool plus the top CDN IPs.
190
191Two scans run in parallel:
192
193 1. IP scan — TCP reachability + RTT for the Cloudflare IP pool.
194 2. SNI scan — TLS handshakes against --sni-target (default 1.1.1.1,
195 which uses a universal SSL cert and accepts any SNI).
196
197The SNI scan's purpose is to find SNIs that the user's ISP does NOT block;
198it does not tell you which IPs serve which customer domains. Use the IP
199scan results for your profile's connect.host / fallback_ips.`,
200 RunE: func(cmd *cobra.Command, args []string) error {
201 ctx, cancel := installSignalCancel(cmd.Context())
202 defer cancel()
203
204 sniTargetAddr, err := netip.ParseAddr(sniTarget)
205 if err != nil {
206 return fmt.Errorf("invalid --sni-target: %w", err)
207 }
208
209 fmt.Fprintf(cmd.OutOrStdout(),
210 "Scanning %d Cloudflare IPs and %d SNI candidates (SNI probes → %s)...\n",
211 len(scanner.DefaultCloudflareIPs), len(scanner.DefaultSNICandidates), sniTarget)
212
213 type ipOut struct {
214 results []scanner.IPResult
215 }
216 type sniOut struct {
217 results []scanner.Result
218 }
219 ipCh := make(chan ipOut, 1)
220 sniCh := make(chan sniOut, 1)
221
222 go func() {
223 r := scanner.ProbeIPs(ctx, scanner.DefaultCloudflareIPs, 443,
224 2*time.Second, 16, nil)
225 ipCh <- ipOut{r}
226 }()
227 go func() {
228 r := scanner.ProbeSNIs(ctx, scanner.DefaultSNICandidates,
229 scanner.ProbeConfig{
230 TargetIP: sniTargetAddr,
231 TargetPort: 443,
232 ConnectTimeout: 4 * time.Second,
233 HandshakeTimeout: 4 * time.Second,
234 Concurrency: 16,
235 }, nil)
236 sniCh <- sniOut{r}
237 }()
238 ips := (<-ipCh).results
239 snis := (<-sniCh).results
240
241 rankedIPs := scanner.RankIPs(ips)

Callers 1

newScanRootCmdFunction · 0.85

Calls 8

ProbeIPsFunction · 0.92
ProbeSNIsFunction · 0.92
RankIPsFunction · 0.92
RankSNIsFunction · 0.92
installSignalCancelFunction · 0.85
writeIPTableFunction · 0.85
writeSNITableFunction · 0.85
minFunction · 0.85

Tested by

no test coverage detected