#!/bin/bash
# -------------------------------------------------------------------
# Copyright (C) 2016 by Intevation GmbH
# Author(s):
# Sascha Wilde <wilde@intevation.de>

# This program is free software under the GNU GPL (>=v2)
# Read the file COPYING coming with the software for details.
# -------------------------------------------------------------------

ME=`basename $0`

ip2hex()
{
  for o in $( echo "$1" | tr '.' ' ' )
  do
    printf "%02X" $o
  done ; echo
}

usage()
{
  echo "Usage: $ME IP ..."
  exit -1
}


# Main

[ $# -gt 0 ] || usage

for ip in "$@"
do
  if egrep -q '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' <<<"$ip"
  then
      ip2hex "$ip"
  else
    usage
  fi
done
