# README
netselect
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.
Usage
netselect
available as Commnad-Line tool and Go library.
Commnad-Line
netselect [options] <host(s)>
Examples
$ 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.
Go Library
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)
}
fastestHosts := netSelector.Hosts // Fastest hosts in ASC order
Read the API documentation for more information on the library usage.
Installation
$ go get github.com/pgollangi/netselect/cmd/netselect
$ netselect
Manual
- Download and install binary from the latest release.
- Recommended: add
netselect
executable to your $PATH.
Building from source
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.
Install Go
To download and install Go
, please refer to the Go documentation. Please download Go 1.14.x
or above.
Clone this repository
$ git clone https://gitlab.com/pgollangi/netselect.git
$ cd netselect
Build
$ go build cmd/netselect/netselect.go
$ netselect
Notice for linux users
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.
Contributing
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!
License
Copyright © Prasanna Kumar