feat: 增加了对发包的时间管理控制

This commit is contained in:
Leo
2023-01-18 19:19:19 +08:00
parent 326034b41e
commit b9b18f5efa
7 changed files with 21 additions and 10 deletions

View File

@@ -34,7 +34,7 @@ func Excute() {
"method (incremented by each probe, default is 33434), or initial seq for \"icmp\" (incremented as well, default from 1), or some constant" +
"destination port for other methods (with default of 80 for \"tcp\", 53 for \"udp\", etc.)"})
numMeasurements := parser.Int("q", "queries", &argparse.Options{Default: 3, Help: "Set the number of probes per each hop"})
parallelRequests := parser.Int("", "parallel-requests", &argparse.Options{Default: 18, Help: "Set ParallelRequests number. It should be 1 when there is a multi-routing."})
parallelRequests := parser.Int("", "parallel-requests", &argparse.Options{Default: 18, Help: "Set ParallelRequests number. It should be 1 when there is a multi-routing"})
maxHops := parser.Int("m", "max-hops", &argparse.Options{Default: 30, Help: "Set the max number of hops (max TTL to be reached)"})
dataOrigin := parser.Selector("d", "data-provider", []string{"IP.SB", "IPInfo", "IPInsight", "IPAPI.com"}, &argparse.Options{Default: "LeoMoeAPI",
Help: "Choose IP Geograph Data Provider [LeoMoeAPI,IP.SB, IPInfo, IPInsight, IPAPI.com]"})
@@ -49,6 +49,8 @@ func Excute() {
src_addr := parser.String("s", "source", &argparse.Options{Help: "Use source src_addr for outgoing packets"})
src_dev := parser.String("D", "dev", &argparse.Options{Help: "Use the following Network Devices as the source address in outgoing packets"})
router := parser.Flag("R", "route", &argparse.Options{Help: "Show Routing Table [Provided By BGP.Tools]"})
packet_interval := parser.Int("z", "send-time", &argparse.Options{Default: 0, Help: "Set the time interval for sending every packet. Useful when some routers use rate-limit for ICMP messages."})
ttl_interval := parser.Int("i", "ttl-time", &argparse.Options{Default: 500, Help: "Set the time interval for sending packets groups by TTL. Useful when some routers use rate-limit for ICMP messages."})
str := parser.StringPositional(&argparse.Options{Help: "IP Address or domain name"})
err := parser.Parse(os.Args)
@@ -58,7 +60,7 @@ func Excute() {
fmt.Print(parser.Usage(err))
return
}
printer.Version()
if *ver {
printer.CopyRight()
os.Exit(0)
@@ -66,6 +68,10 @@ func Excute() {
domain := *str
if *port == 0 {
*port = 80
}
if *fast_trace {
fastTrace.FastTest(*tcp, *output)
if *output {
@@ -139,6 +145,8 @@ func Excute() {
DestIP: ip,
DestPort: *port,
MaxHops: *maxHops,
PacketInterval: *packet_interval,
TTLInterval: *ttl_interval,
NumMeasurements: *numMeasurements,
ParallelRequests: *parallelRequests,
RDns: !*noRdns,

View File

@@ -79,8 +79,7 @@ func RealtimePrinter(res *trace.Result, ttl int) {
}
fmt.Fprintf(color.Output, " %s", color.New(color.FgHiGreen, color.Bold).Sprintf("%-16s", whoisFormat[0]))
}
if res.Hops[ttl][i].Geo.Country == "" {
if len(res.Hops[ttl][i].Geo.Country) <= 1 {
res.Hops[ttl][i].Geo.Country = "LAN Address"
}

View File

@@ -47,7 +47,7 @@ func (t *ICMPTracer) PrintFunc() {
}
}
}
<-time.After(100 * time.Millisecond)
<-time.After(200 * time.Millisecond)
}
}
@@ -84,8 +84,9 @@ func (t *ICMPTracer) Execute() (*Result, error) {
for i := 0; i < t.NumMeasurements; i++ {
t.wg.Add(1)
go t.send(ttl)
<-time.After(time.Millisecond * time.Duration(t.Config.PacketInterval))
}
<-time.After(time.Millisecond * 100)
<-time.After(time.Millisecond * time.Duration(t.Config.TTLInterval))
}
t.wg.Wait()

View File

@@ -48,7 +48,7 @@ func (t *ICMPTracerv6) PrintFunc() {
}
}
<-time.After(100 * time.Millisecond)
<-time.After(200 * time.Millisecond)
}
}
@@ -85,8 +85,9 @@ func (t *ICMPTracerv6) Execute() (*Result, error) {
for i := 0; i < t.NumMeasurements; i++ {
t.wg.Add(1)
go t.send(ttl)
<-time.After(time.Millisecond * time.Duration(t.Config.PacketInterval))
}
<-time.After(time.Millisecond * 100)
<-time.After(time.Millisecond * time.Duration(t.Config.TTLInterval))
}
// for ttl := t.BeginHop; ttl <= t.MaxHops; ttl++ {
// if t.final != -1 && ttl > t.final {

View File

@@ -90,7 +90,7 @@ func (t *TCPTracer) Execute() (*Result, error) {
if t.AsyncPrinter != nil {
for {
t.AsyncPrinter(&t.res)
time.Sleep(50 * time.Millisecond)
time.Sleep(200 * time.Millisecond)
}
}

View File

@@ -27,6 +27,8 @@ type Config struct {
Quic bool
IPGeoSource ipgeo.Source
RDns bool
PacketInterval int
TTLInterval int
RealtimePrinter func(res *Result, ttl int)
AsyncPrinter func(res *Result)
}

View File

@@ -73,7 +73,7 @@ func (t *UDPTracer) Execute() (*Result, error) {
if t.AsyncPrinter != nil {
for {
t.AsyncPrinter(&t.res)
time.Sleep(50 * time.Millisecond)
time.Sleep(200 * time.Millisecond)
}
}
}()