Skip to content

💻 A CLI tool and Go library to find the fastest site based on the lowest ICMP latency.

License

Notifications You must be signed in to change notification settings

pgollangi/netselect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

build Go Report Card GitHub go.mod Go version GitHub release (latest by date) PkgGoDev Maintainability Code Climate technical debt License: MIT Say Thanks!

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.

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.

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.

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)
}

results, err := netSelector.Select()

fastestHosts := results // Fastest hosts in ASC order

Read the API documentation for more information on the library usage.

Installation

Scoop

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

Homebrew

brew install pgollangi/tap/netselect

Updating:

brew upgrade netselect

Go

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

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

MIT

Copyright © Prasanna Kumar