improve: rDNS 解析等待时间过长

This commit is contained in:
Leo
2023-01-17 20:08:57 +08:00
parent cdec6cbd8d
commit ce1c773996
2 changed files with 24 additions and 8 deletions

View File

@@ -56,6 +56,7 @@ func Excute() {
// In case of error print error and print usage
// This can also be done by passing -h or --help flags
fmt.Print(parser.Usage(err))
return
}
if *ver {
@@ -65,11 +66,6 @@ func Excute() {
domain := *str
if domain == "" {
fmt.Print(parser.Usage(err))
return
}
if *fast_trace {
fastTrace.FastTest(*tcp, *output)
if *output {
@@ -79,6 +75,11 @@ func Excute() {
os.Exit(0)
}
if domain == "" {
fmt.Print(parser.Usage(err))
return
}
capabilities_check()
// return

View File

@@ -116,10 +116,25 @@ type Hop struct {
}
func (h *Hop) fetchIPData(c Config) (err error) {
timeout := time.Millisecond * 800
if c.RDns && h.Hostname == "" {
ptr, err := net.LookupAddr(h.Address.String())
if err == nil && len(ptr) > 0 {
h.Hostname = ptr[0]
result := make(chan []string)
go func() {
r, err := net.LookupAddr(h.Address.String())
if err != nil {
result <- nil
} else {
result <- r
}
}()
select {
case ptr := <-result:
// process result
if err == nil && len(ptr) > 0 {
h.Hostname = ptr[0]
}
case <-time.After(timeout):
// handle timeout
}
}
if c.IPGeoSource != nil && h.Geo == nil {