Skip to content

Instantly share code, notes, and snippets.

@aachyee
aachyee / cidr2ip
Created September 24, 2020 10:14 — forked from deardooley/cidr2ip
cidr to ip range or list. This script prints the ip ranges for a cidr by default. Full ip lists can be obtained with the -a or --all flags.
#!/usr/bin/env bash
# Print usage
function usage {
echo -n "$(basename $0) CIDR...
$(basename $0) [OPTION] CIDR...
This script prints the ip range or full list of ip addresses for one or more CIDR.
Options:
@aachyee
aachyee / shimo-sshuttle
Created September 24, 2020 10:10 — forked from toonetown/shimo-sshuttle
Connects to sshuttle tunnel using Shimo
#!/bin/bash
# Function to convert cidr to a mask
cidr2mask () {
# Number of args to shift, 255..255, first non-255 byte, zeroes
set -- $(( 5 - (${1} / 8) )) 255 255 255 255 $(( (255 << (8 - (${1} % 8))) & 255 )) 0 0 0
[ ${1} -gt 1 ] && shift ${1} || shift
echo ${1-0}.${2-0}.${3-0}.${4-0}
}
_cidr2mask()
{
local i mask=""
local full_octets=$(($1 / 8))
local partial_octet=$(($1 % 8))
for((i = 0; i < 4; i += 1))
do
if [ $i -lt $full_octets ]
then
@aachyee
aachyee / cidr2mask
Created September 24, 2020 10:08 — forked from linuxenko/cidr2mask
cidr2mask() {
local i mask=""
local full_octets=$(($1/8))
local partial_octet=$(($1%8))
for ((i=0;i<4;i+=1)); do
if [ $i -lt $full_octets ]; then
mask+=255
elif [ $i -eq $full_octets ]; then
mask+=$((256 - 2**(8-$partial_octet)))
#!/bin/bash
# Customize this
domain="indigobio.com"
ns1="8.8.8.8"
ns2="4.2.2.2"
ndots="2"
usage() {
echo
@aachyee
aachyee / gist:f170aa43fee299b9a9465bfcab789fdd
Created September 24, 2020 10:02 — forked from gswallow/gist:5586747
Find netmask / network address / broadcast address / supposed gateway from an IP/cidr pair
cidr2mask() {
local mask=""
local netaddr=""
local bcast=""
local gateway=""
local full_octets=$(($2/8))
local partial_octet=$(($2%8))
ipparts=($(echo $1 | tr "." "\n"))
#!/bin/bash
#wget -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | awk -F\| '/CN\|ipv4/ { printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > /etc/chnroute.txt
netcalc(){
local IFS='.' ip i
local -a oct msk
read -ra oct <<<"$1"
read -ra msk <<<"$2"
// 2018.12.03 Atienza, Chris
// Given a slash specified network (ie: 10.1.1.1/24) returns the low and hi IPs in the defined range
// does not exclude any special reserved addresses
function _cidrToRange(cidr) {
var range = [2];
cidr = cidr.split('/');
var cidr_1 = parseInt(cidr[1])
range[0] = long2ip((ip2long(cidr[0])) & ((-1 << (32 - cidr_1))));
start = ip2long(range[0])
@aachyee
aachyee / decimal2ip.sh
Created September 24, 2020 09:52 — forked from TimaGribanov/decimal2ip.sh
Converting IPs
#!/bin/bash
#Converting decimal to binary
##Source: https://stackoverflow.com/questions/55239476/awk-convert-decimal-to-binary
gawk '
function d2b(d, b) {
while(d) {
b=d%2b
d=int(d/2)
}
# Template
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$here = Split-Path -Path $MyInvocation.MyCommand.Path -Parent
# ArrayList
$al = New-Object System.Collections.ArrayList
# OrderedDictionary
$od = [ordered]{