Giter VIP home page Giter VIP logo

netselect's Introduction

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

netselect's People

Contributors

deepsourcebot avatar dependabot-preview[bot] avatar dependabot[bot] avatar pgollangi avatar renovate-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

fossabot

netselect's Issues

Fix Homebrew formula

Installing with brew fails with Homebrew 4.1.15 in last macOS:

$ brew install pgollangi/tap/netselect
Error: pgollangi/tap/netselect: wrong number of arguments (given 1, expected 0)

Since it was made with GoReleaser it may need to be regenerated again: pgollangi/homebrew-tap/netselect.rb

Publish scoop and homebrw packages from goreleaser

Is your feature request related to a problem? Please describe.
Currently users can only download installer from release page. Adding scoop installation would make it easy to install for windows users.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

dockerfile
Dockerfile
github-actions
.github/workflows/build.yml
  • actions/setup-go v2
  • actions/checkout v2
  • codecov/codecov-action v1
.github/workflows/build_docs.yml
  • actions/checkout v2
.github/workflows/release.yml
  • actions/checkout v2
  • actions/setup-go v2
  • goreleaser/goreleaser-action v2
gomod
go.mod
  • go 1.14
  • github.com/MakeNowJust/heredoc v1.0.0
  • github.com/briandowns/spinner v1.11.1
  • github.com/pgollangi/go-ping v1.0.0
  • github.com/spf13/cobra v1.1.1

  • Check this box to trigger a request for Renovate to run again on this repository

Display status / loading on executing command

Is your feature request related to a problem? Please describe.
Currently, on running command netselect, console will wait until finishing pings of all provided hosts. It will be good if there is a loading message displayed while this operation is happening on background.

Describe the solution you'd like
This can addressed by using simple spinner

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.