-
Notifications
You must be signed in to change notification settings - Fork 1
/
myip.sh
executable file
·74 lines (60 loc) · 1.72 KB
/
myip.sh
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
72
73
74
#!/bin/bash
export n=9
# echo $argv
if [[ $1 = '-n' ]]; then
export n=$2
fi
if [[ $1 = "-f" ]]; then
export n=30
# else
fi
if [ $n=9 ]; then
echo "~/bin/myip.sh:"
fi
# https://linuxize.com/post/bash-if-else-statement/
# echo [ $argv 0=$0 1=$1 2=$2 n=$n ]
if [ $n -eq 8 ]; then
echo "~/bin/myip.sh:"
fi
date +"%D %T"
echo "\$OSTYPE=$OSTYPE SHELL=$SHELL"
printf "\n My external IP address: \e[1m"
curl -s http://ipecho.net/plain
# https://misc.flogisoft.com/bash/tip_colors_and_formatting
printf "\n\e[36m ip route interface: "
ip route get 8.8.8.8 2>/dev/null| awk '{print $5}'
if [[ "$OSTYPE" == "linux-gnu" ]]; then
# ...
printf " \e[92mip addr show eth0\e[37m\n"
ip addr show eth0 | grep inet
elif [[ "$OSTYPE" == "darwin18" ]]; then
# Mac OSX
printf "\e[35m ifconfig en0\e[37m\n"
# ip addr show
ifconfig en0 | grep inet
elif [[ "$OSTYPE" == "linux-gnueabihf" ]]; then
# Raspberry ARM
ifconfig eth0 | grep inet
#elif [[ "$OSTYPE" == "cygwin" ]]; then
# # POSIX compatibility layer and Linux environment emulation for Windows
#elif [[ "$OSTYPE" == "msys" ]]; then
# # Lightweight shell and GNU utilities compiled for Windows (part of MinGW)
elif [[ "$OSTYPE" == "win32" ]]; then
# I'm not sure this can happen: Windows
ifconfig /all
else
printf "\e[35m Unknown IP (OSTYPE=$OSTYPE)"
fi
# colors prinft: [34 - blue, 31-red 35m - Magenta 92 -lt green 37m - lt gray
# \e[0m reset \e1m - bold
printf " \n"
if [ -f ~/bin/screenfetch-dev ]; then
# echo "bash ~/bin/screenfetch-dev:"
/bin/bash -c ~/bin/screenfetch-dev | head -n $n
else
./screenfetch-dev | head -n $n
fi
printf "\n\e[0m"
df -h | grep -v none
# bash ~/bin/myip.sh -f > ~/index.html
# ~/bin/myhttp -p 3000