Skip to content

Commit

Permalink
feat: 增加了对发包的时间管理控制
Browse files Browse the repository at this point in the history
  • Loading branch information
sjlleo committed Jan 18, 2023
1 parent 326034b commit b9b18f5
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 10 deletions.
12 changes: 10 additions & 2 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]"})
Expand All @@ -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)
Expand All @@ -58,14 +60,18 @@ func Excute() {
fmt.Print(parser.Usage(err))
return
}

printer.Version()
if *ver {
printer.CopyRight()
os.Exit(0)
}

domain := *str

if *port == 0 {
*port = 80
}

if *fast_trace {
fastTrace.FastTest(*tcp, *output)
if *output {
Expand Down Expand Up @@ -139,6 +145,8 @@ func Excute() {
DestIP: ip,
DestPort: *port,
MaxHops: *maxHops,
PacketInterval: *packet_interval,
TTLInterval: *ttl_interval,
NumMeasurements: *numMeasurements,
ParallelRequests: *parallelRequests,
RDns: !*noRdns,
Expand Down
3 changes: 1 addition & 2 deletions printer/realtime_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
5 changes: 3 additions & 2 deletions trace/icmp_ipv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (t *ICMPTracer) PrintFunc() {
}
}
}
<-time.After(100 * time.Millisecond)
<-time.After(200 * time.Millisecond)
}
}

Expand Down Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions trace/icmp_ipv6.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (t *ICMPTracerv6) PrintFunc() {
}
}

<-time.After(100 * time.Millisecond)
<-time.After(200 * time.Millisecond)
}
}

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion trace/tcp_ipv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 2 additions & 0 deletions trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion trace/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}()
Expand Down

0 comments on commit b9b18f5

Please sign in to comment.