github.com/nxtrace/NTrace-core@v1.3.1-0.20240513132635-39169291e8c9/printer/basic.go (about) 1 package printer 2 3 import ( 4 "fmt" 5 "github.com/nxtrace/NTrace-core/config" 6 "github.com/nxtrace/NTrace-core/trace" 7 "github.com/nxtrace/NTrace-core/util" 8 "net" 9 10 "github.com/fatih/color" 11 ) 12 13 var version = config.Version 14 var buildDate = config.BuildDate 15 var commitID = config.CommitID 16 17 func Version() { 18 fmt.Fprintf(color.Output, "%s %s %s %s\n", 19 color.New(color.FgWhite, color.Bold).Sprintf("%s", "NextTrace"), 20 color.New(color.FgHiBlack, color.Bold).Sprintf("%s", version), 21 color.New(color.FgHiBlack, color.Bold).Sprintf("%s", buildDate), 22 color.New(color.FgHiBlack, color.Bold).Sprintf("%s", commitID), 23 ) 24 } 25 26 func CopyRight() { 27 sponsor() 28 fmt.Fprintf(color.Output, "\n%s\n%s %s\n%s %s\n%s %s, %s, %s, %s\n%s %s\n", 29 color.New(color.FgCyan, color.Bold).Sprintf("%s", "NextTrace CopyRight"), 30 //color.New(color.FgGreen, color.Bold).Sprintf("%s", "Contact Us"), 31 //color.New(color.FgWhite, color.Bold).Sprintf("%s", "Feedback Email:"), 32 //color.New(color.FgHiBlack, color.Bold).Sprintf("%s", "nt@moeqing.com"), 33 //color.New(color.FgWhite, color.Bold).Sprintf("%s", "HomePage:"), 34 //color.New(color.FgHiBlack, color.Bold).Sprintf("%s", "github.com/nxtrace"), 35 color.New(color.FgWhite, color.Bold).Sprintf("%s", "Honorary Founder:"), 36 color.New(color.FgHiBlue, color.Bold).Sprintf("%s", "Leo"), 37 //color.New(color.FgHiBlack, color.Bold).Sprintf("%s", "i@leo.moe"), 38 color.New(color.FgWhite, color.Bold).Sprintf("%s", "Project Chair:"), 39 color.New(color.FgHiBlue, color.Bold).Sprintf("%s", "Tso"), 40 color.New(color.FgWhite, color.Bold).Sprintf("%s", "Core-Developer:"), 41 color.New(color.FgHiBlue, color.Bold).Sprintf("%s", "Leo"), 42 //color.New(color.FgHiBlack, color.Bold).Sprintf("%s", "i@leo.moe"), 43 color.New(color.FgHiBlue, color.Bold).Sprintf("%s", "Vincent"), 44 //color.New(color.FgHiBlack, color.Bold).Sprintf("%s", "i@vincent.moe"), 45 color.New(color.FgHiBlue, color.Bold).Sprintf("%s", "zhshch"), 46 //color.New(color.FgHiBlack, color.Bold).Sprintf("%s", "zhshch@athorx.com"), 47 color.New(color.FgHiBlue, color.Bold).Sprintf("%s", "Tso"), 48 //color.New(color.FgHiBlack, color.Bold).Sprintf("%s", "tsosunchia@gmail.com"), 49 color.New(color.FgWhite, color.Bold).Sprintf("%s", "Infra Maintainer:"), 50 color.New(color.FgHiBlue, color.Bold).Sprintf("%s", "Tso"), 51 //color.New(color.FgWhite, color.Bold).Sprintf("%s", "NOC Manager:"), 52 //color.New(color.FgHiBlue, color.Bold).Sprintf("%s", "YekongTAT"), 53 //color.New(color.FgHiBlack, color.Bold).Sprintf("%s", "tsosunchia@gmail.com"), 54 ) 55 //PluginCopyRight() 56 } 57 58 func sponsor() { 59 italic := "\x1b[3m%s\x1b[0m" 60 formatted := fmt.Sprintf(italic, "(Listed in no particular order)") 61 62 fmt.Fprintf(color.Output, "%s\n%s\n%s\n%s\n%s\n", 63 color.New(color.FgCyan, color.Bold).Sprintf("%s", "NextTrace Sponsored by"), 64 color.New(color.FgHiYellow, color.Bold).Sprintf("%s", "· DMIT.io"), 65 color.New(color.FgHiYellow, color.Bold).Sprintf("%s", "· Misaka.io"), 66 color.New(color.FgHiYellow, color.Bold).Sprintf("%s", "· Saltyfish.io"), 67 color.New(color.FgHiBlack, color.Bold).Sprintf("%s", formatted), 68 ) 69 } 70 71 //func PluginCopyRight() { 72 // fmt.Fprintf(color.Output, "%s\n%s %s\n\n", 73 // color.New(color.FgGreen, color.Bold).Sprintf("%s", "NextTrace Map Plugin Author"), 74 // color.New(color.FgWhite, color.Bold).Sprintf("%s", "Tso"), 75 // color.New(color.FgHiBlack, color.Bold).Sprintf("%s", "tsosunchia@gmail.com"), 76 // ) 77 //} 78 79 func PrintTraceRouteNav(ip net.IP, domain string, dataOrigin string, maxHops int, packetSize int) { 80 fmt.Println("IP Geo Data Provider: " + dataOrigin) 81 if util.EnableHidDstIP == "" { 82 if ip.String() == domain { 83 fmt.Printf("traceroute to %s, %d hops max, %d bytes packets\n", ip.String(), maxHops, packetSize) 84 } else { 85 fmt.Printf("traceroute to %s (%s), %d hops max, %d bytes packets\n", ip.String(), domain, maxHops, packetSize) 86 } 87 } else { 88 fmt.Printf("traceroute to %s, %d hops max, %d bytes packets\n", util.HideIPPart(ip.String()), maxHops, packetSize) 89 } 90 } 91 92 func applyLangSetting(h *trace.Hop) { 93 if len(h.Geo.Country) <= 1 { 94 //打印h.geo 95 if h.Geo.Whois != "" { 96 h.Geo.Country = h.Geo.Whois 97 } else { 98 if h.Geo.Source != "LeoMoeAPI" { 99 h.Geo.Country = "网络故障" 100 h.Geo.CountryEn = "Network Error" 101 } else { 102 h.Geo.Country = "未知" 103 h.Geo.CountryEn = "Unknown" 104 } 105 } 106 } 107 108 if h.Lang == "en" { 109 if h.Geo.Country == "Anycast" { 110 111 } else if h.Geo.Prov == "骨干网" { 112 h.Geo.Prov = "BackBone" 113 } else if h.Geo.ProvEn == "" { 114 h.Geo.Country = h.Geo.CountryEn 115 } else { 116 if h.Geo.CityEn == "" { 117 h.Geo.Country = h.Geo.ProvEn 118 h.Geo.Prov = h.Geo.CountryEn 119 h.Geo.City = "" 120 } else { 121 h.Geo.Country = h.Geo.CityEn 122 h.Geo.Prov = h.Geo.ProvEn 123 h.Geo.City = h.Geo.CountryEn 124 } 125 } 126 } 127 128 }