Skip to content

Instantly share code, notes, and snippets.

@sahal
Created August 10, 2014 12:20
Show Gist options
  • Save sahal/304e92d21370bfc1c293 to your computer and use it in GitHub Desktop.
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.
#! /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
@iamjenechka
Copy link

cool :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment