diff --git a/go.mod b/go.mod index 92a74dc..8c5bde6 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect + github.com/logrusorgru/aurora v2.0.3+incompatible github.com/stretchr/testify v1.6.1 // indirect gopkg.in/alecthomas/kingpin.v2 v2.2.6 ) diff --git a/go.sum b/go.sum index fa14a76..93a45c6 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2c github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8= +github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/request.go b/request.go index 13e5662..c66665e 100644 --- a/request.go +++ b/request.go @@ -8,6 +8,8 @@ import ( "strings" "sync" "time" + + "github.com/logrusorgru/aurora" ) var dlSizes = [...]int{350, 500, 750, 1000, 1500, 2000, 2500, 3000, 3500, 4000} @@ -15,7 +17,7 @@ var ulSizes = [...]int{100, 300, 500, 800, 1000, 1500, 2500, 3000, 3500, 4000} / func downloadTest(sURL string, latency time.Duration) float64 { dlURL := strings.Split(sURL, "/upload")[0] - fmt.Printf("Download Test: ") + fmt.Printf("%-14s: ", "Download Test") wg := new(sync.WaitGroup) // Warming up @@ -66,7 +68,7 @@ func downloadTest(sURL string, latency time.Duration) float64 { } func uploadTest(sURL string, latency time.Duration) float64 { - fmt.Printf("Upload Test: ") + fmt.Printf("%-14s: ", "Upload Test") wg := new(sync.WaitGroup) // Warm up @@ -184,6 +186,6 @@ func pingTest(sURL string) time.Duration { } } - fmt.Println("Latency:", (l / 2.0)) + fmt.Printf("\n%-14s: %v\n", "Latency", aurora.Gray(24, (l/2.0).Truncate(time.Microsecond))) return l / 2.0 } diff --git a/server.go b/server.go index 544ba92..c38d9b3 100644 --- a/server.go +++ b/server.go @@ -8,6 +8,8 @@ import ( "math" "sort" "strconv" + + "github.com/logrusorgru/aurora" ) // Server information @@ -142,9 +144,7 @@ func (l ServerList) Show() { // Show : show server information func (s Server) Show() { - fmt.Printf(" \n") - fmt.Printf("Target Server: [%4s] %8.2fkm ", s.ID, s.Distance) - fmt.Printf(s.Name + " (" + s.Country + ") by " + s.Sponsor + "\n") + fmt.Printf("%-6s : %s %.2fkm (%s/%s) by %s\n", "Target", aurora.Magenta(s.ID), s.Distance, aurora.Magenta(s.Name), s.Country, aurora.Gray(12, s.Sponsor)) } // StartTest : start testing to the servers. @@ -163,8 +163,8 @@ func (svrs Servers) StartTest() { func (svrs Servers) ShowResult() { fmt.Printf(" \n") if len(svrs) == 1 { - fmt.Printf("Download: %5.2f Mbit/s\n", svrs[0].DLSpeed) - fmt.Printf("Upload: %5.2f Mbit/s\n", svrs[0].ULSpeed) + fmt.Printf("%-13s : %s\n", "Download", aurora.Gray(24, fmt.Sprintf("%5.2f Mbit/s", svrs[0].DLSpeed))) + fmt.Printf("%-13s : %s\n", "Upload", aurora.Gray(24, fmt.Sprintf("%5.2f Mbit/s", svrs[0].ULSpeed))) } else { for _, s := range svrs { fmt.Printf("[%4s] Download: %5.2f Mbit/s, Upload: %5.2f Mbit/s\n", s.ID, s.DLSpeed, s.ULSpeed) diff --git a/speedtest.go b/speedtest.go index 50a33ea..f5f14ff 100644 --- a/speedtest.go +++ b/speedtest.go @@ -70,7 +70,7 @@ func setSourceAddr(iface string) (ip net.IP) { } var ( - app = kingpin.New("speedtest", "Run a speedtest").Author("Newlode") + app = kingpin.New("speedtest-fpngfw", "Run a speedtest from a Forcepoint NGFW. Writen by Newlode www.newlode.io").Author("Sébastien Boulet @ Newlode Groupe - www.newlode.io") insecure = app.Flag("insecure", "Disable TLS certificate verify").Short('i').Default("true").Bool() iface = app.Flag("iface", "Force the use of IFACE for this test").Short('I').String() showList = app.Flag("list", "Show available speedtest.net servers").Short('l').Bool() @@ -82,7 +82,7 @@ var ( func main() { var ip net.IP - kingpin.Version("1.0.6") + kingpin.Version("1.0.7") kingpin.MustParse(app.Parse(os.Args[1:])) setTimeout() diff --git a/user.go b/user.go index 9e99926..130066e 100644 --- a/user.go +++ b/user.go @@ -5,6 +5,8 @@ import ( "encoding/xml" "fmt" "io/ioutil" + + "github.com/logrusorgru/aurora" ) // User information @@ -51,6 +53,6 @@ func fetchUserInfo() User { // Show user location func (u *User) Show(ip string) { if u.IP != "" { - fmt.Println("Testing From IP " + ip + "/" + u.IP + " (" + u.Isp + ") [" + u.Lat + ", " + u.Lon + "]") + fmt.Printf("%-6s : %s/%s (%s) [%s,%s]\n", "Source", aurora.Gray(18, ip), aurora.Gray(24, u.IP), aurora.Cyan(u.Isp), aurora.Gray(12, u.Lat), aurora.Gray(12, u.Lon)) } }