dns lookup concurrently

This commit is contained in:
juzeon
2024-02-11 20:29:56 -05:00
committed by yuhan6665
parent fee556f668
commit 4ba7e103ef
2 changed files with 28 additions and 10 deletions
+10 -10
View File
@@ -7,6 +7,7 @@ import (
"log/slog"
"net"
"net/netip"
"regexp"
"strings"
)
@@ -73,17 +74,12 @@ func Iterate(reader io.Reader) <-chan Host {
}
continue
}
ips, err := net.LookupIP(line)
if err == nil {
if ValidateDomainName(line) {
// domain
for _, ip = range ips {
if ip.To4() != nil || enableIPv6 {
hostChan <- Host{
IP: ip,
Origin: line,
Type: HostTypeDomain,
}
}
hostChan <- Host{
IP: nil,
Origin: line,
Type: HostTypeDomain,
}
continue
}
@@ -95,6 +91,10 @@ func Iterate(reader io.Reader) <-chan Host {
}()
return hostChan
}
func ValidateDomainName(domain string) bool {
r := regexp.MustCompile(`(?m)^[A-Za-z0-9\-.]+$`)
return r.MatchString(domain)
}
func ExistOnlyOne(arr []string) bool {
exist := false
for _, item := range arr {