This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Customize this | |
| domain="indigobio.com" | |
| ns1="8.8.8.8" | |
| ns2="4.2.2.2" | |
| ndots="2" | |
| usage() { | |
| echo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cidr2mask() { | |
| local mask="" | |
| local netaddr="" | |
| local bcast="" | |
| local gateway="" | |
| local full_octets=$(($2/8)) | |
| local partial_octet=$(($2%8)) | |
| ipparts=($(echo $1 | tr "." "\n")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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]{ |