-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathip_address_private
executable file
·35 lines (29 loc) · 1.04 KB
/
ip_address_private
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
#!/usr/bin/env bash
# allow invokation of related scripts in this dir
scriptdir=`dirname "$BASH_SOURCE"`
PATH="$scriptdir:$PATH"
if [ x"`uname -a | grep -i buntu | wc -l 2>/dev/null`" == x"1" ] ; then
# Ubuntu
ip_address=`echo $(hostname -I)`
echo $ip_address
# else: ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'
exit
fi
if [ x"`uname -a | grep -i Linux | wc -l 2>/dev/null`" == x"1" ] ; then
# Redhat
ip_address=`echo $(hostname -I)`
echo $ip_address
# else: ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'
exit
fi
# Else
# Mac OSx
# lo0 0xff000000 127.0.0.1 ::1
# en1 00:23:12:55:3b:34 0xffffff00 192.168.0.255 192.168.0.141 fe80::223:12ff:fe55:3b34%en1
ip_interfaces | while read interface macaddr mask subnet ip_address xx
do
case "$interface" in
"en0"|"en1") echo $ip_address; exit;;
*) continue;;
esac
done