Posts netselect - find fastest site based on lowest ICMP latency
Post
Cancel

netselect - find fastest site based on lowest ICMP latency

💻 netselect is an open source CLI tool as well as Go library to find the fastest host(s) based on the lowest ICMP latency.

It’s a handy tool to choose a mirror for apt, or just to compare sites to each other. Under the hood it’s just an ICMP ping.

Try it and let me know your thoughts. I would greatly appreciate any kind of feedback.

Repo: https://github.com/pgollangi/netselect

  • Star if you find this tool useful.
  • Open an Issue if you come accross any problem using tool.
  • Submit a PR if you would like an improvement.

Features

  • 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.

Usage

netselect available as Commnad-Line tool and Go library.

Command-Line

1
2
3
netselect [options] <host(s)>
netselect -v
netselect --help

For example:

1
2
3
4
5
$ 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)

For more information on CLI usage, please refer dev.pgollangi.com/netselect.

Go Library

Here is a simple example that finds fastest host(s) using library:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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()
if err != nil {
    panic(err)
}

fastestHosts := results // Fastest hosts in ASC order

For more information on library usage, please refer API documentation on pkg.go.dev

Installation

Scoop

1
2
scoop bucket add pgollangi-bucket https://github.com/pgollangi/scoop-bucket.git
scoop install netselect

Homebrew

1
brew install pgollangi/tap/netselect

Updating:

1
brew upgrade netselect

Go

1
2
go get github.com/pgollangi/netselect/cmd/netselect
netselect

Manual

  1. Download and install binary from the latest release.
  2. Recommended: add netselect executable to your $PATH.

Caveats

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

1
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

1
sudo sysctl -w net.ipv4.ping_group_range="0   2147483647"
This post is licensed under CC BY 4.0 by the author.