Skip to content

Commit 4ba7e10

Browse files
juzeonyuhan6665
authored andcommitted
dns lookup concurrently
1 parent fee556f commit 4ba7e10

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

scanner.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ var TLSDictionary = map[uint16]string{
1717
}
1818

1919
func ScanTLS(host Host, out chan<- string) {
20+
if host.IP == nil {
21+
ips, err := net.LookupIP(host.Origin)
22+
if err != nil {
23+
slog.Debug("Failed to lookup", "origin", host.Origin, "err", err)
24+
return
25+
}
26+
var arr []net.IP
27+
for _, ip := range ips {
28+
if ip.To4() != nil || enableIPv6 {
29+
arr = append(arr, ip)
30+
}
31+
}
32+
if len(arr) == 0 {
33+
slog.Debug("No IP found", "origin", host.Origin)
34+
return
35+
}
36+
host.IP = arr[0]
37+
}
2038
hostPort := net.JoinHostPort(host.IP.String(), strconv.Itoa(port))
2139
conn, err := net.DialTimeout("tcp", hostPort, time.Duration(timeout)*time.Second)
2240
if err != nil {

utils.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log/slog"
88
"net"
99
"net/netip"
10+
"regexp"
1011
"strings"
1112
)
1213

@@ -73,17 +74,12 @@ func Iterate(reader io.Reader) <-chan Host {
7374
}
7475
continue
7576
}
76-
ips, err := net.LookupIP(line)
77-
if err == nil {
77+
if ValidateDomainName(line) {
7878
// domain
79-
for _, ip = range ips {
80-
if ip.To4() != nil || enableIPv6 {
81-
hostChan <- Host{
82-
IP: ip,
83-
Origin: line,
84-
Type: HostTypeDomain,
85-
}
86-
}
79+
hostChan <- Host{
80+
IP: nil,
81+
Origin: line,
82+
Type: HostTypeDomain,
8783
}
8884
continue
8985
}
@@ -95,6 +91,10 @@ func Iterate(reader io.Reader) <-chan Host {
9591
}()
9692
return hostChan
9793
}
94+
func ValidateDomainName(domain string) bool {
95+
r := regexp.MustCompile(`(?m)^[A-Za-z0-9\-.]+$`)
96+
return r.MatchString(domain)
97+
}
9898
func ExistOnlyOne(arr []string) bool {
9999
exist := false
100100
for _, item := range arr {

0 commit comments

Comments
 (0)