File: gl-get-ipadd

package info (click to toggle)
clonezilla 5.12.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,580 kB
  • sloc: sh: 41,014; perl: 193; python: 59; makefile: 26
file content (21 lines) | stat: -rwxr-xr-x 562 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
# Author: Steven Shiau <steven _at_ clonezilla org>
# License: GPL
# Description: Get the IP address of network card interface

ethx=$1
export LC_ALL=C

Usage() {
  echo "Get the IP address of network card interface" 
  echo "Usage:"
  echo "$(basename $0) INTERFACE"
  echo "Ex: $(basename $0) eth0"
}

[ -z "$ethx" ] && Usage && exit 1
if ! LC_ALL=C ifconfig -a 2>/dev/null | grep -i -q "\<$ethx\>"; then
   exit 1
fi
LC_ALL=C ifconfig $ethx | grep -A1 $ethx | grep -v $ethx | grep "inet addr" | sed -e 's/^.*inet addr:\([0-9\.]\+\).*$/\1/'
exit 0