Created
August 10, 2014 12:20
-
-
Save sahal/304e92d21370bfc1c293 to your computer and use it in GitHub Desktop.
Convert hex encoded ip from mibbit or cgi:irc to dot-decimal format. Useful script from my ircop days.
This file contains 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 | |
# ./ipc.sh $1 | |
# by: Sahal Ansari github.com/sahal | |
# | |
# desc: takes input ($1) in form of hex encoded ip from mibbit or cgi:irc | |
# returns ip in dot-decimal format | |
# | |
# use in irssi: /exec (-o) ~/ipc hexip | |
#ready the input | |
# capitalize input (not necessary - i was using bc earlier &it requires caps) | |
# separate every two characters with a ":" (useful when i use cut later) | |
input=`echo $1 | tr [a-z] [A-Z] | sed 's/../&:/g;s/:$//'` | |
#print the ip | |
for (( i=1; i<=4; i++ )) | |
do | |
printf "%d" 0x`echo $input | cut -d ":" -f$i` | |
if [ "$i" -ne "4" ]; | |
then echo -ne "."; | |
fi | |
done | |
# need that extra return... | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cool :)