-
Notifications
You must be signed in to change notification settings - Fork 11
/
ipmi_sim_lancontrol
executable file
·72 lines (56 loc) · 1.13 KB
/
ipmi_sim_lancontrol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#! /bin/sh
# ipmi_sim_lancontrol - provide link addresses to ipmi_sim for device $1
# See lan_config_program in ipmi_lan(5)
#
# 2015-05-06 Noel Burton-Krahn <[email protected]>
set -eu
# arguments: dev op var
# network interface
dev=$1
# get or set. This script just supports get
op=$2
# var name
var=$3
# my default gateway device
gw_dev=$(ip route | sed -ne 's/default via [.0-9]* dev \([^ ]*\) .*/\1/p')
link_ip() {
ip -o -4 addr list $1 | sed -ne 's/.* inet \([.0-9]*\)\/.*/\1/p'
}
link_mac() {
ip -o link list $1 | sed -ne 's/.* link\/ether \([:0-9a-f]*\) .*/\1/p'
}
link_subnet() {
ifconfig $1 | sed -n -e 's/.*Mask:\([.0-9]*\).*/\1/p'
}
get_val() {
case $var in
ip_addr_src)
echo "dhcp"
;;
ip_addr)
link_ip $dev
;;
mac_addr)
link_mac $dev
;;
subnet_mask)
link_subnet $dev
;;
default_gw_ip_addr)
link_ip $gw_dev
;;
default_gw_mac_addr)
link_mac $gw_dev
;;
backup_gw_ip_addr)
link_ip $gw_dev
;;
backup_gw_mac_addr)
link_mac $gw_dev
;;
esac
}
if [ $op = "get" ]; then
val=$(get_val $var)
echo "$var: $val"
fi