A CLI tool as well as library to select the fastest host based on the lowest ICMP latency written in Go (golang), inspired by apenwarr/netselect debian package.
It’s a handy tool to choose a mirror for apt, or just to compare sites to each other. Under the hood it’s an ICMP ping.
- Finds the fastest host(s) in terms of network connectivity.
- Run desired concurent findings to get faster results. Use flag
--concurrent
. - Customize no. of ping attempt to perform for each host to get accurate mean response time. Use flag
--attempts
. - Display only top
n
results on output. Use flag--output
. - Optionally, direct
netselect
to send "unprivileged" pings via UDP for non-sudo users. Use--privileged=false
.
netselect
available as Commnad-Line tool and Go library.
netselect [options] <host(s)>
$ netselect google.com google.in google.us
google.com 55 ms 100% ok ( 3/ 3)
google.in 56 ms 100% ok ( 3/ 3)
google.us 59 ms 100% ok ( 3/ 3)
Read the documentation for more information on the CLI usage.
Here is a simple example that finds fastest hosts:
hosts := []*netselect.Host{
&netselect.Host{Address: "google.in"},
&netselect.Host{Address: "google.com"},
}
netSelector, err :=netselect.NewNetSelector(hosts)
if err != nil {
panic(err)
}
results, err := netSelector.Select()
fastestHosts := results // Fastest hosts in ASC order
Read the API documentation for more information on the library usage.
scoop bucket add pgollangi-bucket https://github.com/pgollangi/scoop-bucket.git
scoop install netselect
brew install pgollangi/tap/netselect
Updating:
brew upgrade netselect
$ go get github.com/pgollangi/netselect/cmd/netselect
$ netselect
- Download and install binary from the latest release.
- Recommended: add
netselect
executable to your $PATH.
netselect
CLI is written in the Go programming language, so to build the CLI yourself, you first need to have Go installed and configured on your machine.
To download and install Go
, please refer to the Go documentation. Please download Go 1.14.x
or above.
$ git clone https://gitlab.com/pgollangi/netselect.git
$ cd netselect
$ go build cmd/netselect/netselect.go
$ netselect
netelect
implements ICMP ping using both raw socket and UDP. It needs to be run as a root user.
Alternatley, you can use setcap
to allow netselect
to bind to raw sockets
setcap cap_net_raw=+ep /bin/netselect
If you do not wish to do all this, you can use flag --privileged=false
to send an "unprivileged" ping via UDP. This must be enabled by setting
sudo sysctl -w net.ipv4.ping_group_range="0 2147483647"
See this blog and the Go icmp library for more details.
Thanks for considering contributing to this project!
Please read the Contributions and Code of conduct.
Feel free to open an issue or submit a pull request!
Copyright © Prasanna Kumar