chore: Classic Printer Change

This commit is contained in:
Leo
2023-05-23 20:00:42 +08:00
parent 903b6f232d
commit b88d5292da
2 changed files with 19 additions and 2 deletions

View File

@@ -46,7 +46,7 @@ func Excute() {
dn42 := parser.Flag("", "dn42", &argparse.Options{Help: "DN42 Mode"})
output := parser.Flag("o", "output", &argparse.Options{Help: "Write trace result to file (RealTimePrinter ONLY)"})
tablePrint := parser.Flag("t", "table", &argparse.Options{Help: "Output trace results as table"})
classicPrint := parser.Flag("c", "classic", &argparse.Options{Help: "Classic Output trace results like BestTrace"})
classicPrint := parser.Flag("c", "classic", &argparse.Options{Help: "An Output Easy to Parse"})
beginHop := parser.Int("f", "first", &argparse.Options{Default: 1, Help: "Start from the first_ttl hop (instead from 1)"})
maptrace := parser.Flag("M", "map", &argparse.Options{Help: "Disable Print Trace Map"})
ver := parser.Flag("v", "version", &argparse.Options{Help: "Print version info and exit"})
@@ -191,7 +191,7 @@ func Excute() {
if !*tablePrint {
if *classicPrint {
conf.RealtimePrinter = printer.ClassicPrinter
conf.RealtimePrinter = printer.EasyPrinter
} else {
if *output {
conf.RealtimePrinter = tracelog.RealtimePrinter

17
printer/easy.go Normal file
View File

@@ -0,0 +1,17 @@
package printer
import (
"fmt"
"github.com/xgadget-lab/nexttrace/trace"
)
func EasyPrinter(res *trace.Result, ttl int) {
for i := range res.Hops[ttl] {
if res.Hops[ttl][i].Address == nil {
fmt.Printf("%d|*||||||\n", ttl+1)
continue
}
fmt.Printf("%d|%s|%s|%s|%s|%s|%s|%s|%s|%.4f|%.4f\n", ttl+1, res.Hops[ttl][i].Address.String(), res.Hops[ttl][i].Hostname, res.Hops[ttl][i].Geo.Asnumber, res.Hops[ttl][i].Geo.Country, res.Hops[ttl][i].Geo.Prov, res.Hops[ttl][i].Geo.City, res.Hops[ttl][i].Geo.District, res.Hops[ttl][i].Geo.Owner, res.Hops[ttl][i].Geo.Lat, res.Hops[ttl][i].Geo.Lng)
}
}