Debian Codegraph @

scripts/bin/drbl-get-ipadd

raw symbols SCIP
1 #!/bin/bash
2 # Authors: Steven Shiau <steven _at_ clonezilla org>, Ceasar Sun <ceasar _at_ nchc org tw>
3 # License: GPL
4 # Description: Get the IP address of network card interface
5
6 # Load DRBL setting and functions
7 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
8
9 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
10
11 ethx=$1
12 export LC_ALL=C
13
14 Usage() {
15 echo "Get the IP address of network card interface"
16 echo "Usage:"
17 echo "$(basename $0) INTERFACE"
18 echo "Ex: $(basename $0) eth0"
19 }
20
21 # For physical NIC, the output of "ifconfig -a" (Debian, Ubuntu and Fedora <=14) is like:
22 # eth0 Link encap:Ethernet HWaddr 00:11:aa:bb:cc:dd
23 # For ppp0 NIC, it's like:
24 # ppp0 Link encap:Point-to-Point Protocol
25 # Ref: http://sourceforge.net/projects/drbl/forums/forum/394008/topic/3855959
26 # For Fedora 17, the output of "ifconfig -a" is like (//Note// An extra ":"):
27 # eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
28 # inet 192.168.120.192 netmask 255.255.255.0 broadcast 192.168.120.255
29 # inet6 fe80::20c:29ff:fe97:5d0f prefixlen 64 scopeid 0x20<link>
30 # ether 00:0c:29:97:5d:0f txqueuelen 1000 (Ethernet)
31 # RX packets 1998 bytes 179313 (175.1 KiB)
32 # RX errors 0 dropped 0 overruns 0 frame 0
33 # TX packets 1305 bytes 198243 (193.5 KiB)
34 # TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
35 [ -z "$ethx" ] && Usage && exit 1
36 if ! LC_ALL=C ip link show dev $ethx >/dev/null 2>&1; then
37 exit 1
38 fi
39 LC_ALL=C ip addr show dev $ethx | awk '/inet / {print $2}' | cut -d/ -f1
40 exit 0