You are hereiptohex (convert an ipaddress into hexadecimal)

iptohex (convert an ipaddress into hexadecimal)


Script: iptohex

No error checking, just a simple time saver. Converts an ipaddress into hexadecimal suitable for use by tftp tools and pxe booting. The builtin command gethostip does this also, I include the script incase someone finds it useful.
Example:

uphill@surrey[1]: iptohex 10.168.192.134
0AA8C086

#!/bin/bash
 
IPADDR=$1
 
if [ x${IPADDR}x = xx ]; then
	echo "usage: $0 <ipaddress>"
	exit 1
fi
 
for octet in `echo $IPADDR |tr '.' ' '`
do
	printf "%02X" "$octet"
 
done
echo

Trackback URL for this post:

http://ramblings.narrabilis.com/wp/trackback/162
Tags