Compare commits
No commits in common. "14955ffb2b4c5d16ecf68b4efc10a80d4c01d8da" and "ce0d30666b5fda0c6aded76193569220b9db723b" have entirely different histories.
14955ffb2b
...
ce0d30666b
115
ptrstream.go
115
ptrstream.go
@ -520,7 +520,6 @@ func main() {
|
|||||||
seed := flag.Int64("s", 0, "Seed for IP generation (0 for random)")
|
seed := flag.Int64("s", 0, "Seed for IP generation (0 for random)")
|
||||||
shard := flag.String("shard", "", "Shard specification (e.g., 1/4 for first shard of 4)")
|
shard := flag.String("shard", "", "Shard specification (e.g., 1/4 for first shard of 4)")
|
||||||
loop := flag.Bool("l", false, "Loop continuously after completion")
|
loop := flag.Bool("l", false, "Loop continuously after completion")
|
||||||
jsonOutput := flag.Bool("j", false, "Output NDJSON to stdout (no TUI)")
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
shardNum, totalShards, err := parseShardArg(*shard)
|
shardNum, totalShards, err := parseShardArg(*shard)
|
||||||
@ -671,97 +670,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if *jsonOutput {
|
|
||||||
// JSON-only mode
|
|
||||||
jobs := make(chan string, cfg.concurrency)
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
|
|
||||||
// Start workers
|
|
||||||
for i := 0; i < cfg.concurrency; i++ {
|
|
||||||
wg.Add(1)
|
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
for ip := range jobs {
|
|
||||||
var response DNSResponse
|
|
||||||
var err error
|
|
||||||
var server string
|
|
||||||
|
|
||||||
if len(cfg.dnsServers) > 0 {
|
|
||||||
response, server, err = lookupWithRetry(ip, cfg)
|
|
||||||
if idx := strings.Index(server, ":"); idx != -1 {
|
|
||||||
server = server[:idx]
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
names, err := net.LookupAddr(ip)
|
|
||||||
if err == nil {
|
|
||||||
response = DNSResponse{Names: names, RecordType: "PTR"}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil || len(response.Names) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr := ""
|
|
||||||
for _, name := range response.Names {
|
|
||||||
if cleaned := strings.TrimSpace(strings.TrimSuffix(name, ".")); cleaned != "" {
|
|
||||||
ptr = cleaned
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ptr == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
record := struct {
|
|
||||||
Seen string `json:"seen"`
|
|
||||||
IP string `json:"ip"`
|
|
||||||
Nameserver string `json:"nameserver"`
|
|
||||||
Record string `json:"record"`
|
|
||||||
RecordType string `json:"record_type"`
|
|
||||||
TTL uint32 `json:"ttl"`
|
|
||||||
}{
|
|
||||||
Seen: time.Now().Format(time.RFC3339),
|
|
||||||
IP: ip,
|
|
||||||
Nameserver: server,
|
|
||||||
Record: response.Target,
|
|
||||||
RecordType: response.RecordType,
|
|
||||||
TTL: response.TTL,
|
|
||||||
}
|
|
||||||
|
|
||||||
if response.RecordType != "CNAME" {
|
|
||||||
record.Record = ptr
|
|
||||||
}
|
|
||||||
|
|
||||||
if data, err := json.Marshal(record); err == nil {
|
|
||||||
fmt.Println(string(data))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Feed IPs to workers
|
|
||||||
for {
|
|
||||||
stream, err := golcg.IPStream("0.0.0.0/0", shardNum, totalShards, int(*seed), nil)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "Error creating IP stream: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for ip := range stream {
|
|
||||||
jobs <- ip
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cfg.loop {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
close(jobs)
|
|
||||||
wg.Wait()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
jobs := make(chan string, cfg.concurrency)
|
jobs := make(chan string, cfg.concurrency)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@ -838,26 +746,23 @@ func writeNDJSON(cfg *Config, timestamp time.Time, ip, server, ptr, recordType,
|
|||||||
}
|
}
|
||||||
|
|
||||||
record := struct {
|
record := struct {
|
||||||
Seen string `json:"seen"`
|
Timestamp string `json:"timestamp"`
|
||||||
IP string `json:"ip"`
|
IPAddr string `json:"ip_addr"`
|
||||||
Nameserver string `json:"nameserver"`
|
DNSServer string `json:"dns_server"`
|
||||||
Record string `json:"record"`
|
PTRRecord string `json:"ptr_record"`
|
||||||
RecordType string `json:"record_type"`
|
RecordType string `json:"record_type"`
|
||||||
|
Target string `json:"target,omitempty"`
|
||||||
TTL uint32 `json:"ttl"`
|
TTL uint32 `json:"ttl"`
|
||||||
}{
|
}{
|
||||||
Seen: timestamp.Format(time.RFC3339),
|
Timestamp: timestamp.Format(time.RFC3339),
|
||||||
IP: ip,
|
IPAddr: ip,
|
||||||
Nameserver: server,
|
DNSServer: server,
|
||||||
Record: target, // For CNAME records, use the target
|
PTRRecord: ptr,
|
||||||
RecordType: recordType,
|
RecordType: recordType,
|
||||||
|
Target: target,
|
||||||
TTL: ttl,
|
TTL: ttl,
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's not a CNAME, use the PTR record
|
|
||||||
if recordType != "CNAME" {
|
|
||||||
record.Record = ptr
|
|
||||||
}
|
|
||||||
|
|
||||||
if data, err := json.Marshal(record); err == nil {
|
if data, err := json.Marshal(record); err == nil {
|
||||||
cfg.mu.Lock()
|
cfg.mu.Lock()
|
||||||
cfg.outputFile.Write(data)
|
cfg.outputFile.Write(data)
|
||||||
|
Loading…
Reference in New Issue
Block a user