Skip to content

Commit 52f047d

Browse files
committed
Add --output-ips flag for plain IP list export (CLI + TUI auto-generate)
1 parent 805a828 commit 52f047d

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

cmd/scan.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func init() {
6464
scanCmd.Flags().Bool("skip-ping", false, "skip ICMP ping step")
6565
scanCmd.Flags().Bool("skip-nxdomain", false, "skip NXDOMAIN hijack check")
6666
scanCmd.Flags().Bool("edns", false, "include EDNS payload size check (filters resolvers that don't support EDNS)")
67+
scanCmd.Flags().String("output-ips", "", "write plain IP list (one per line) to this file")
6768
scanCmd.Flags().Int("top", 10, "number of top results to display")
6869
rootCmd.AddCommand(scanCmd)
6970
}
@@ -79,6 +80,7 @@ func runScan(cmd *cobra.Command, args []string) error {
7980
skipNXD, _ := cmd.Flags().GetBool("skip-nxdomain")
8081
ednsMode, _ := cmd.Flags().GetBool("edns")
8182
topN, _ := cmd.Flags().GetInt("top")
83+
outputIPs, _ := cmd.Flags().GetString("output-ips")
8284

8385
if outputFile == "" {
8486
return fmt.Errorf("--output / -o flag is required")
@@ -201,7 +203,16 @@ func runScan(cmd *cobra.Command, args []string) error {
201203

202204
printSummary(report, topN, totalTime, domain)
203205

204-
return scanner.WriteChainReport(report, outputFile)
206+
if err := scanner.WriteChainReport(report, outputFile); err != nil {
207+
return err
208+
}
209+
if outputIPs != "" {
210+
if err := scanner.WriteIPList(report.Passed, outputIPs); err != nil {
211+
return fmt.Errorf("writing IP list: %w", err)
212+
}
213+
fmt.Fprintf(os.Stderr, " %s✔ IP list written to %s (%d IPs)%s\n", colorGreen, outputIPs, len(report.Passed), colorReset)
214+
}
215+
return nil
205216
}
206217

207218
func pad(s string, width int) string {

internal/scanner/output.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"os"
7+
"strings"
78
"time"
89
)
910

@@ -36,6 +37,15 @@ func WriteReport(results []Result, path string) error {
3637
return os.WriteFile(path, data, 0644)
3738
}
3839

40+
func WriteIPList(passed []IPRecord, path string) error {
41+
var b strings.Builder
42+
for _, r := range passed {
43+
b.WriteString(r.IP)
44+
b.WriteByte('\n')
45+
}
46+
return os.WriteFile(path, []byte(b.String()), 0644)
47+
}
48+
3949
func PrintStats(mode string, results []Result, duration time.Duration) {
4050
var passCount, failCount int
4151
for _, r := range results {

internal/tui/screen_running.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ func launchScan(ctx context.Context, ips []string, cfg ScanConfig, steps []scann
166166
var writeErr error
167167
if cfg.OutputFile != "" {
168168
writeErr = scanner.WriteChainReport(report, cfg.OutputFile)
169+
// Also write plain IP list alongside JSON
170+
if writeErr == nil {
171+
ipFile := strings.TrimSuffix(cfg.OutputFile, ".json") + "_ips.txt"
172+
_ = scanner.WriteIPList(report.Passed, ipFile)
173+
}
169174
}
170175
doneCh <- scanDoneMsg{report: report, elapsed: elapsed, writeErr: writeErr}
171176
}()

0 commit comments

Comments
 (0)