Giter VIP home page Giter VIP logo

go-which-network's Introduction

Which Network?

This amazing go utility does an astounding thing:

  • Given an argument list with at least one of a "CIDR-block=key" pair and an "IPaddr/interface-name/hostname" (can have multiple of either or both)...
  • Outputs a tab-delimited sequence of the CIDR-block keys to which IPaddr/interface/hostname matches.

So, like, I want to know if I'm on subnet A or subnet B. Suppose "eth0" is my main interface (and let's suppose its address is 192.168.1.17)

ethan@no-puppet ~$ which-network 192.168.100.0/24=subnet-A 192.168.1.0/24=subnet-B eth0
eth0	192.168.1.17	subnet-B

The output gives us tab-delimited columns of:

  • The input interface or hostname or IP address
  • The IP address used for its matching test
  • The key given in association with the network (CIDR block) that matched the address.

If a named interface/host has multiple IP addresses, they'll all be considered (independently).

All matches are listed. The order of input controls the order of evaluation (which is done network first).

Suppose I had both my eth0 interface and a VPN tunnel tun0 with IP address 192.168.100.4 (subnet A in the earlier example). And suppose we had a catch-all network in there as well.

ethan@no-puppet ~$ which-network 192.168.100.0/24=subnet-A \
  192.168.1.0/24=subnet-B \
  0.0.0.0/0=default \
  eth0 \
  tun0
tun0	192.168.100.4	subnet-A
eth0	192.168.1.17	subnet-B
eth0	192.168.1.17	default
tun0	192.168.100.4	default

Here's an example that includes hostnames. These networks are mostly stupid, but they illustrate the usage. (The "nopuppet" name is my local hostname, named for a moment of soaring oratory during the 2016 US Presidential debates.)

ethan@nopuppet ~$ which-network \
  127.0.0.0/24=local/X \
  127.0.1.0/24=local/Y \
  172.16.24.0/24=/my/special/vpn \
  0.0.0.0/0=catch-all \
  localhost \
  nopuppet \
  127.0.0.1 \
  127.0.1.1 \
  tun0 google.com \
  amazonaws.com
localhost	127.0.0.1	local/X
127.0.0.1	127.0.0.1	local/X
nopuppet	127.0.1.1	local/Y
127.0.1.1	127.0.1.1	local/Y
tun0	172.16.24.18	/my/special/vpn
localhost	127.0.0.1	catch-all
nopuppet	127.0.1.1	catch-all
127.0.0.1	127.0.0.1	catch-all
127.0.1.1	127.0.1.1	catch-all
tun0	172.16.24.18	catch-all
google.com	172.217.164.110	catch-all
amazonaws.com	207.171.166.22	catch-all
amazonaws.com	72.21.206.80	catch-all
amazonaws.com	72.21.210.29	catch-all

Building in general

Assumes you've got docker handy.

make clean
make build

You'll get linux and mac versions of the binary.

If you're building within a docker container already, use make build-native.

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.