add lib ip

This commit is contained in:
Xavier Logerais (Numericable - Ingénierie Système) 2013-05-07 15:57:52 +02:00
parent 9fad99b12f
commit 2e5f9792d3

26
libs/ip.bash Normal file
View File

@ -0,0 +1,26 @@
#!/bin/bash
function ip_to_hex ()
{
if test -e "$1" ; then echo "Usage : $0 XXX.XXX.XXX.XXX" ; return ; fi
IFS='.' read -a array <<< "$1"
printf "%02X %02X %02X %02X \n" ${array[0]} ${array[1]} ${array[2]} ${array[3]}
}
function generate_mac_from_ip ()
{
if test -e "$1" ; then echo "Usage : $0 hostname" ; return ; fi
IFS='.' read -a array <<< "$1"
printf " IP HEXA : %02X %02X %02X %02X\n" ${array[0]} ${array[1]} ${array[2]} ${array[3]}
printf " MAC : 52:54:00:%02X:%02X:%02X\n" ${array[1]} ${array[2]} ${array[3]}
printf "DHCP CONFIG : host $1 { hardware ethernet 52:54:00:%02X:%02X:%02X; }\n" ${array[1]} ${array[2]} ${array[3]}
}
function generate_mac_from_hostname ()
{
if test -e "$1" ; then echo "Usage : $0 hostname" ; return ; fi
IFS='.' read -a array <<< "$(ssh admin dig +search +short $1)"
printf " IP HEXA : %02X %02X %02X %02X\n" ${array[0]} ${array[1]} ${array[2]} ${array[3]}
printf " MAC : 52:54:00:%02X:%02X:%02X\n" ${array[1]} ${array[2]} ${array[3]}
printf "DHCP CONFIG : host $1 { hardware ethernet 52:54:00:%02X:%02X:%02X; }\n" ${array[1]} ${array[2]} ${array[3]}
}