## iphex

I wrote a small bash script, that transforms IP addresses into HEX format. The tool consists of 10 lines of bash script

#!/bin/bash
if [ $# -lt 1 ]; then echo "IP-Address to HEX converter" echo "Usage: \"basename$0 IPADDRESS\""
echo "  e.g.    basename $0 127.0.0.1 = $0 127.0.0.1"
else
IP_ADDR=$1 printf '%02X'${IP_ADDR//./ }; echo
fi

I needed the tool to match IP-addresses to HEX files for PXE boot. Normally PXE boot fetches first the MAC-address, and then iteratively for the HEX representation of the IP address, with reducing the number of matching characters. Oracle documents the behavior very nicely for the IP address “192.0.2.91"which matches “C000025B” and the imaginary MAC-address “88:99:AA:BB:CC:DD”. Then the PXE client probes for the following files (in the given order)

/tftpboot/pxelinux.cfg/01-88-99-aa-bb-cc-dd
/tftpboot/pxelinux.cfg/C000025B
/tftpboot/pxelinux.cfg/C000025
/tftpboot/pxelinux.cfg/C00002
/tftpboot/pxelinux.cfg/C0000
/tftpboot/pxelinux.cfg/C000
/tftpboot/pxelinux.cfg/C00
/tftpboot/pxelinux.cfg/C0
/tftpboot/pxelinux.cfg/C

Now, with iphex I can easily convert the more used numerical representation of IP-addresses like 192.168.2.91 into the IMHO not directly visible HEX representation.