Skip to content

Instantly share code, notes, and snippets.

@jerry74
jerry74 / gist:6ab9b7060eca5f85a77c
Created March 28, 2015 09:37
chnroute CID2Mast
#!/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"
@robinsmidsrod
robinsmidsrod / ip_and_netmask2cidr.sh
Created April 11, 2015 20:59
Calculate IPv4 network address and CIDR mask from IP address (dotted quad) and network mask (dotted quad)
# $1 is a decimal number between 0-255
dec2bin () {
[ -z "$1" ] && return
D2B=({0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1})
echo ${D2B[$1]}
}
# $1 is ip address (dotted quad)
# $2 is netmask (dotted quad)
calc_network () {
@lumenpink
lumenpink / knock
Last active September 24, 2020 09:29
Knock 2015.1 - Projeto elaborado na Estácio de Sá Santa Catarina - https://docs.google.com/presentation/d/1G-kDirpN6SyehQw8KUaFqMJARwLrHhw80Y9wdXNNkXQ/edit?usp=sharing
#!/bin/bash
. /usr/local/knock/library
#Lista de portas na ordem da sequencia
ports=(34 1032 43231 456)
#Porta a Ser desbloqueada
safePort=29
#Comando tshark (wireshark para console)
#customizado para exibir apenas
#ip de origem e porta de destino
tshark -n -l -f "tcp and dst 177.70.2.30 and tcp[tcpflags] & (tcp-syn) != 0 and tcp[tcpflags] & (tcp-ack) = 0" -E separator=":" -Tfields -e ip.src -e tcp.dstport |
@jwieder
jwieder / lib_netaddr.awk
Created November 4, 2015 15:41
convert massive subnet lists to CIDR very quickly (280K lines ~15 sec) - h/t ripat
#
# Library with various ip manipulation functions
#
# convert ip ranges to CIDR notation
# str range2cidr(ip2dec("192.168.0.15"), ip2dec("192.168.5.115"))
#
# Credit to Chubler_XL for this brilliant function. (see his post below for non GNU awk)
#
function range2cidr(ipStart, ipEnd, bits, mask, newip) {
@shangjiyu
shangjiyu / iprange2cidr.awk
Last active May 13, 2022 23:26
iprange2cidr awk script
#
# Library with various ip manipulation functions
#
# convert ip ranges to CIDR notation
# str range2cidr(ip2dec("192.168.0.15"), ip2dec("192.168.5.115"))
#
# Credit to Chubler_XL for this brilliant function. (see his post below for non GNU awk)
#
function range2cidr(ipStart, ipEnd, bits, mask, newip) {
@JavaScript-Packer
JavaScript-Packer / (de)obfuscate-IP-address.js
Last active December 29, 2022 16:24
This simple JavaScript function set/utility provides the opportunity to obfuscate an IP address or decipher an obfuscated IP. Made by www.whak.ca
function ip2decimal(ip) {
ip = ip.split(".");
var e, w = 16777216, x = 65536, y = 256, a = eval(ip[0]), b = eval(ip[1]), c = eval(ip[2]), d = eval(ip[3]);
e = a * w + b * x + c * y + d;
return e;
}
function decimal2ip(ip) {
var w = 16777216, x = 65536, y = 256, e = eval(ip), a = e / w, z = e - (a - e % w / w) * w, b = z / x, q = z - (b - z % x / x) * x, c = q / y, d = q - (c - q % y / y) * y;
return parseInt(a) + "." + parseInt(b) + "." + parseInt(c) + "." + parseInt(d);
@kwilczynski
kwilczynski / cidr-to-netmask.sh
Last active February 24, 2026 19:24
CIDR to netmask in bash.
# Return netmask for a given network and CIDR.
cidr_to_netmask() {
value=$(( 0xffffffff ^ ((1 << (32 - $1)) - 1) ))
echo "$(( (value >> 24) & 0xff )).$(( (value >> 16) & 0xff )).$(( (value >> 8) & 0xff )).$(( value & 0xff ))"
}
@alessiomangoni13
alessiomangoni13 / ipresolv.sh
Created September 27, 2016 15:53
Script per la generazione di IP a partire da notazione CIDR
#!/bin/bash
############################
## Methods
############################
prefix_to_bit_netmask() {
prefix=$1;
shift=$(( 32 - prefix ));
bitmask=""
@dllmoe
dllmoe / ip2dec.js
Created October 8, 2016 03:32
ip地址转十进制
#!/usr/bin/nodejs
function showHelp(){
console.log('Usage: ipnum [ip] ...');
}
function convert(ip){
if(typeof ip !== 'string') return false;
if(!/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(ip)) return false;
@cskeeters
cskeeters / broadcast_calc.sh
Created December 8, 2016 19:17
Bash script for calculating network and broadcast addresses from ip and netmask or CIDR Notation
#!/bin/bash
# Calculates network and broadcast based on supplied ip address and netmask
# Usage: broadcast_calc.sh 192.168.0.1 255.255.255.0
# Usage: broadcast_calc.sh 192.168.0.1/24
tonum() {
if [[ $1 =~ ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+) ]]; then