Skip to content

Commit

Permalink
[*]优化DNS解析模块,现在识别更准确了
Browse files Browse the repository at this point in the history
  • Loading branch information
lcvvvv committed Oct 15, 2022
1 parent 152f221 commit d6d895d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/lcvvvv/gonmap

go 1.16

require github.com/miekg/dns v1.1.50
23 changes: 9 additions & 14 deletions type-nmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package gonmap
import (
"context"
"fmt"
"net"
"github.com/miekg/dns"
"strings"
"time"
)
Expand Down Expand Up @@ -367,20 +367,15 @@ func (n *Nmap) sortOfRarity(list ProbeList) ProbeList {
}

//工具函数

func DnsScan(host string, port int) bool {
addr := fmt.Sprintf("%s:%d", host, port)

r := &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
d := net.Dialer{
Timeout: 2 * time.Second,
}
return d.DialContext(ctx, "udp", addr)
},
}
_, err := r.LookupHost(context.Background(), "www.baidu.com")
domainServer := fmt.Sprintf("%s:%d", host, port)
c := dns.Client{
Timeout: 2 * time.Second,
}
m := dns.Msg{}
// 最终都会指向一个ip 也就是typeA, 这样就可以返回所有层的cname.
m.SetQuestion("www.baidu.com.", dns.TypeA)
_, _, err := c.Exchange(&m, domainServer)
if err != nil {
return false
}
Expand Down

0 comments on commit d6d895d

Please sign in to comment.