Skip to content

Instantly share code, notes, and snippets.

@livingston
livingston / IP2Decimal.js
Created January 12, 2010 14:22
converts IP address to decimal format
/* IP2Decimal.js - converts IP address to decimal format
* @author - Livingston Samuel
*/
var IP2Decimal = function (ip) {
var ipSyntax = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/, ipArr, i = 4, decVal = 0;
if (ipSyntax.test(ip)) {
ipArr = ip.split(".");
@tiveone
tiveone / netutils.sh
Created April 27, 2012 05:14
Convert netmask to cidr.
#!/bin/bash
function ::netmask2cidr()
{
case $1 in
0x*)
local hex=${1#0x*} quad=
while [ -n "${hex}" ]; do
local lastbut2=${hex#??*}
quad=${quad}${quad:+.}0x${hex%${lastbut2}*}
_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
@gswallow
gswallow / gist:5586747
Last active September 24, 2020 10:02
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
# Customize this
domain="indigobio.com"
ns1="8.8.8.8"
ns2="4.2.2.2"
ndots="2"
usage() {
echo
@alghanmi
alghanmi / gcc-default-fix.sh
Last active February 26, 2025 05:03
Change the default g++ compiler on MacOS to be the brew version
#
# Make gcc-4.8 the default compiler
# brew installs gcc-4.8, but does not create symlinks for it to be used
# without the version number.
# This script:
# 1. Generate symlinks for all gcc tools installed by brew
# 2. Make brew-installed software the first in path
#
BREW_CMD="brew"
@harasou
harasou / bash
Created August 24, 2014 08:21
シェルスクリプトで IPアドレス計算 ref: http://qiita.com/harasou@github/items/5c14c335388f70e178f5
$ ip2decimal 192.168.0.1
3232235521
$ decimal2ip 3232235521
192.168.0.1
$
$ ip2decimal 255.255.255.0
4294967040
$ cidr2decimal 24
4294967040
@felmoltor
felmoltor / estadisticas.sh
Last active September 24, 2020 09:34
Kippo statistic extraction script
#!/bin/bash
TOPIP=15
TOPUP=30
TOPU=30
TOPP=30
TOPLU=15
TOPLP=15
GEOLITEDB="/home/<username>/maxmind/GeoIPCountryWhois.db" # Use the sqlite3 db created with http://pastebin.com/9WxCy5ks
@CMDann
CMDann / annonthatshit.sh
Created March 3, 2015 12:23
Onion Pi IPTables
#!/bin/bash
# By Frank Danielson @ Bold Apps
IPS=(`ifconfig | grep "inet addr:" | awk -F: '{ print $2 }' | awk '{ print $1 }'`)
MASKS=(`ifconfig | grep "Mask:" | awk -F: '{ print $4 }'`)
BITS=()
i=0
mask2cidr() {
@felmoltor
felmoltor / analyze.new.logs.sh
Last active September 24, 2020 09:37
OVH Apache Access log periodic download
#!/bin/bash
# Author: Felipe Molina (@felmoltor)
# Date: 05/03/2015
# Summary:
# This script analyzes the Apache logs previously downloaded with "download.ovh.logs.sh"
# It compares the requests done yesterday with the whitelist of files of the website contained in "whitelist.files.list"
# If one of the requests is not pressent in this whitelist, the script stores it as suspicious along with the server response
# of the request and finally a summary is sent to your email.