Skip to content

Instantly share code, notes, and snippets.

@jsfaint
Created March 10, 2015 02:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsfaint/33b2e1829b09c50da59f to your computer and use it in GitHub Desktop.
Save jsfaint/33b2e1829b09c50da59f to your computer and use it in GitHub Desktop.
Dump NCSI IP/Mac address using ipmitool
#!/bin/bash
channel_cmd="ipmitool channel info"
lan_cmd="ipmitool lan print"
function is_lan_channel()
{
local chan=$1
$channel_cmd $chan 2>&1 | grep LAN -q
if [[ $? -eq 0 ]]; then
return 1
else
return 0
fi
}
function get_lan_mac()
{
local chan=$1
echo -ne "$chan: "
$lan_cmd $chan | grep -w "MAC Address" | awk '{print $4}'
}
function get_lan_ip()
{
local chan=$1
echo -ne "$chan: "
$lan_cmd $chan | grep -w "IP Address :" | awk '{print $4}'
}
[ -z $1 ] && echo "$0 ip|mac" && exit 1
flag=$1
if [[ $flag != "ip" ]] && [[ $flag != "mac" ]]; then
echo "Unknown parameter($flag), should be 'ip' or 'mac'"
exit 1
fi
for ((i=1; i<11; i++)); do
is_lan_channel $i
if [[ $? -eq 1 ]]; then
if [[ $flag == "ip" ]]; then
get_lan_ip $i
elif [[ $flag == "mac" ]]; then
get_lan_mac $i
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment