Skip to content

Instantly share code, notes, and snippets.

@lopes
Created January 2, 2013 18:51
Show Gist options
  • Save lopes/4436846 to your computer and use it in GitHub Desktop.
Save lopes/4436846 to your computer and use it in GitHub Desktop.
An deprecated IPv4 war dialer written in Shell Script. It's more like an example on how to make bitwise operations in Bash.
#!/bin/bash
str2int(){
local octet int=0
for octet in $(echo $1 | tr "." " "); do
int=$((int << 8))
int=$((int + octet))
done
echo $int
}
int2str(){
local octets int=$1
for index in 1 2 3 4; do
octets="$((int & 255)) $octets"
int=$((int >> 8))
done
echo $octets | tr " " "."
}
ADDR_STR=$1
ADDR_INT=$(str2int "$1")
for ((index=$ADDR_INT; index < 4294967295; ++index)); do
ADDR_STR=$(int2str $index)
echo -n "$ADDR_STR - "
pingy=$(ping -c 3 $ADDR_STR 2>1)
echo "OK"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment