Tuesday, January 1, 2008

Script for Coverting IP to Hex

#!/usr/bin/bash
# Covert Ip addresses to HEX - For setting up TFP server#
# (c)dhanesh
#
echo "Enter IP address :"
read ip
ip=` echo $ip | sed 's/\./ /g'`
printf '%.2x%.2x%.2x%.2x\n' $ip | tr "[:lower:]" "[:upper:]"

2 comments:

Unknown said...

line 3:
ip=` echo $ip sed 's/\./ /g'`

should be:
ip=` echo $ip | sed 's/\./ /g'`

Unknown said...

oh, this post is really old, just noticed now ..

probably a display issue, in the last line the printf output needs to be piped to tr as well:

printf '%.2x%.2x%.2x%.2x\n' $ip tr "[:lower:]" "[:upper:]"

should be:

printf '%.2x%.2x%.2x%.2x\n' $ip | tr "[:lower:]" "[:upper:]"