#!/bin/sh # # IP to hex converter # Handles all three classes of addresses (A, B & C) # # Method: # echo argument into stdin of awk # use awk to separate fields and provide input to dc # use dc to calculate the IP address value and print it out in hex # use awk to pad to 8 bytes, if necessary # # # @(#) convert_to_hex 1.12 88/04/06 # # Copyright (c) 1987 by Sun Microsystems, Inc. # HOME=/; export HOME PATH=/bin:/usr/bin:/etc:/usr/etc:/usr/etc/install/script:/usr/ucb:/a/usr/bin LOG="/usr/etc/install/files/suninstall.log" echo $1 | \ awk 'BEGIN { FS="."; OFS=" "; print "16 o"; } { \ print $1; \ if (NF == 4) { print "256 *", $2, "+ 256 *", $3, "+ 256 *", $4; } \ if (NF == 3) { print "256 *", " 256 *", $2, "+ 256 *", $3; } \ if (NF == 2) { print "256 *", " 256 *", " 256 *", $2; } \ print "+ p"; }' | \ dc | \ awk 'BEGIN { ORS=""; } { \ for (i = length($1); i < 8; i++) { print "0"; }; print $1, "\n" }'