mirror of
https://github.com/XTLS/RealiTLScanner.git
synced 2026-09-25 23:57:55 +03:00
dns lookup concurrently
This commit is contained in:
+18
@@ -17,6 +17,24 @@ var TLSDictionary = map[uint16]string{
|
||||
}
|
||||
|
||||
func ScanTLS(host Host, out chan<- string) {
|
||||
if host.IP == nil {
|
||||
ips, err := net.LookupIP(host.Origin)
|
||||
if err != nil {
|
||||
slog.Debug("Failed to lookup", "origin", host.Origin, "err", err)
|
||||
return
|
||||
}
|
||||
var arr []net.IP
|
||||
for _, ip := range ips {
|
||||
if ip.To4() != nil || enableIPv6 {
|
||||
arr = append(arr, ip)
|
||||
}
|
||||
}
|
||||
if len(arr) == 0 {
|
||||
slog.Debug("No IP found", "origin", host.Origin)
|
||||
return
|
||||
}
|
||||
host.IP = arr[0]
|
||||
}
|
||||
hostPort := net.JoinHostPort(host.IP.String(), strconv.Itoa(port))
|
||||
conn, err := net.DialTimeout("tcp", hostPort, time.Duration(timeout)*time.Second)
|
||||
if err != nil {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user