polish and add README.md
This commit is contained in:
parent
0ec09475d9
commit
5e41065084
|
@ -0,0 +1,64 @@
|
|||
# name5
|
||||
|
||||
the main DNS code that powers professorOak's aggressive latteral resolver
|
||||
|
||||
##### `go run ./ aol.com`
|
||||
|
||||
```
|
||||
---------name-
|
||||
name: aol.com.
|
||||
212.82.100.150
|
||||
124.108.115.100
|
||||
98.136.103.23
|
||||
74.6.136.150
|
||||
.,.,.
|
||||
name: w2.src.vip.tw1.yahoo.com.
|
||||
2406:2000:fc:c5f::a000
|
||||
.,.,.
|
||||
name: w2.src.vip.ir2.yahoo.com.
|
||||
2a00:1288:110:c305::1:9000
|
||||
.,.,.
|
||||
name: w2.src.vip.bf1.yahoo.com.
|
||||
2001:4998:124:1507::4000
|
||||
.,.,.
|
||||
name: w2.src.vip.sg3.yahoo.com.
|
||||
106.10.248.150
|
||||
2406:2000:e4:1605::4000
|
||||
.,.,.
|
||||
name: w2.src.vip.gq1.yahoo.com.
|
||||
2001:4998:24:120d::5000
|
||||
-------------
|
||||
|
||||
|
||||
----------ptr-
|
||||
ip: 2406:2000:e4:1605::4000
|
||||
ptr: w2.src.vip.sg3.yahoo.com.
|
||||
+ - + - +
|
||||
ip: 2001:4998:124:1507::4000
|
||||
ptr: w2.src.vip.bf1.yahoo.com.
|
||||
+ - + - +
|
||||
ip: 2a00:1288:110:c305::1:9000
|
||||
ptr: w2.src.vip.ir2.yahoo.com.
|
||||
+ - + - +
|
||||
ip: 106.10.248.150
|
||||
ptr: w2.src.vip.sg3.yahoo.com.
|
||||
+ - + - +
|
||||
ip: 124.108.115.100
|
||||
ptr: w2.src.vip.tw1.yahoo.com.
|
||||
+ - + - +
|
||||
ip: 74.6.136.150
|
||||
ptr: w2.src.vip.bf1.yahoo.com.
|
||||
+ - + - +
|
||||
ip: 98.136.103.23
|
||||
ptr: w2.src.vip.gq1.yahoo.com.
|
||||
+ - + - +
|
||||
ip: 212.82.100.150
|
||||
ptr: w2.src.vip.ir2.yahoo.com.
|
||||
+ - + - +
|
||||
ip: 2406:2000:fc:c5f::a000
|
||||
ptr: w2.src.vip.tw1.yahoo.com.
|
||||
+ - + - +
|
||||
ip: 2001:4998:24:120d::5000
|
||||
ptr: w2.src.vip.gq1.yahoo.com.
|
||||
-------------
|
||||
```
|
|
@ -6,34 +6,54 @@ import (
|
|||
"git.tcp.direct/kayos/name5"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var nores []string
|
||||
dnm := name5.NewDNSMap(os.Args[1])
|
||||
println("\n----------ptr-\n")
|
||||
func printPTR(dnm *name5.DNSMap) {
|
||||
println("\n----------ptr-")
|
||||
defer println("-------------\n")
|
||||
var count = 0
|
||||
for kv := range dnm.IPToPTR.IterBuffered() {
|
||||
println("ip:", kv.Key, "ptr:", kv.Val.(string))
|
||||
println("ip:", kv.Key, "\nptr:", kv.Val.(string))
|
||||
if count == dnm.IPToPTR.Count()-1 {
|
||||
break
|
||||
}
|
||||
println("+ - + - +")
|
||||
count++
|
||||
}
|
||||
println("\n-------------\n")
|
||||
}
|
||||
|
||||
func printNameToIP(dnm *name5.DNSMap) (nores []string) {
|
||||
println("\n---------name-")
|
||||
defer println("-------------\n")
|
||||
var count = 0
|
||||
for kv := range dnm.NameToIPs.IterBuffered() {
|
||||
vals := kv.Val.(*name5.IPName)
|
||||
if len(vals.IPs) == 0 {
|
||||
nores = append(nores, kv.Key)
|
||||
continue
|
||||
}
|
||||
println("name:", kv.Key)
|
||||
if len(vals.IPs) == 1 {
|
||||
print(vals.IPs[0] + "\n")
|
||||
continue
|
||||
prefix := ".,.,.\n"
|
||||
if count == 0 {
|
||||
prefix = ""
|
||||
}
|
||||
println(prefix+"name:", kv.Key)
|
||||
for _, addr := range vals.IPs {
|
||||
println(addr)
|
||||
}
|
||||
println("- - - - -")
|
||||
if count == dnm.NameToIPs.Count()-1 {
|
||||
break
|
||||
}
|
||||
count++
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func main() {
|
||||
dnm := name5.NewDNSMap(os.Args[1])
|
||||
nores := printNameToIP(dnm)
|
||||
printPTR(dnm)
|
||||
if len(nores) < 1 {
|
||||
return
|
||||
}
|
||||
println("\nobjects with no results:")
|
||||
println("\nobjects without unique (or any) IPs:\n")
|
||||
for _, name := range nores {
|
||||
println(name)
|
||||
}
|
||||
|
|
21
dnsmap.go
21
dnsmap.go
|
@ -20,7 +20,10 @@ type IPName struct {
|
|||
type DNSMap struct {
|
||||
IPToPTR cmap.ConcurrentMap
|
||||
NameToIPs cmap.ConcurrentMap // map[string]*IPName
|
||||
Working *int64
|
||||
// SeenIPs is a map of IP addresses that have been seen in the DNS query results
|
||||
// in theory this will be merged into an out of scope key/value store when the DNSMap is destroyed
|
||||
SeenIPs cmap.ConcurrentMap // map[string][]string
|
||||
Working *int64
|
||||
|
||||
born *time.Time
|
||||
ctx context.Context
|
||||
|
@ -37,6 +40,7 @@ func (dnm *DNSMap) initCounters() {
|
|||
func (dnm *DNSMap) initMaps() {
|
||||
dnm.IPToPTR = cmap.New()
|
||||
dnm.NameToIPs = cmap.New() // make(map[string]*IPName)
|
||||
dnm.SeenIPs = cmap.New() // make(map[string][]string)
|
||||
}
|
||||
|
||||
// NewDNSMap creates a new DNSMap type
|
||||
|
@ -148,6 +152,21 @@ func (dnm *DNSMap) process(in *dns.Msg) {
|
|||
if len(addrs) < 0 || in.Question[0].Qtype == dns.TypePTR {
|
||||
return
|
||||
}
|
||||
var unseenIPs []string
|
||||
for _, addr := range addrs {
|
||||
if !dnm.SeenIPs.Has(addr) {
|
||||
unseenIPs = append(unseenIPs, addr)
|
||||
dnm.SeenIPs.Set(addr, []string{question})
|
||||
continue
|
||||
}
|
||||
oldList, ok := dnm.SeenIPs.Get(addr)
|
||||
if !ok {
|
||||
log.Panic().Msg("unexpected error")
|
||||
}
|
||||
newList := append(oldList.([]string), question)
|
||||
dnm.SeenIPs.Set(addr, newList)
|
||||
}
|
||||
addrs = unseenIPs
|
||||
current, ok := dnm.NameToIPs.Get(question)
|
||||
if !ok {
|
||||
dnm.NameToIPs.Set(question, &IPName{Name: question, IPs: addrs})
|
||||
|
|
Loading…
Reference in New Issue