-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiplist.sh
executable file
·67 lines (54 loc) · 1.89 KB
/
iplist.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
#!/bin/bash
# If file is not found, record that previous ips do not exist, and create the files
if [ ! -f ~/.previousexternaladdr ]; then
echo "No Previous External IP Recorded" > ~/.previousexternaladdr
fi
if [ ! -f ~/.previousinternaladdr ]; then
echo "No Previous Internal IP Recorded" > ~/.previousinternaladdr
fi
# Line break
echo
# Stores current external ip into file using ipecho.net service
echo "Current External IP: "
curl -s ipecho.net/plain > ~/.externaladdr
# Prints file with external IP stored in it
cat ~/.externaladdr
# Line break
echo
# Line break
echo
# Stores current local ip into file using native mac command on the interface en0 (default)
echo "Current Local IP: "
ipconfig getifaddr en0 > ~/.internaladdr
# Prints file with internal ip stored in it
cat ~/.internaladdr
# Line break
echo
# init rant
# Not gonna lie, this shit is weird.
# So I was having this problem where I would get an extra line break (or not enough) depending on the circumstance.
# After hours of trial and error, I find that this fixes the problem.
# I realize this is a conditional which is always true. It's illogical.
# Ask bash devs why this works, because I really don't know. But it does!
# Prints external ip that was generated last time the script was run
echo "Previous External IP: "
a=`cat ~/.previousexternaladdr`
echo $a
echo "No Previous External IP Recorded" > ~/.linefix
# Prints file with external IP (or lack thereof) stored in it
b=`cat ~/.linefix`
if [ "$a" != "$b" ]; then
echo
else
echo
fi
# Prints local ip that was generated last time the script was run
echo "Previous Local IP: "
cat ~/.previousinternaladdr
# Line break
echo
# Stores new current ip as previous in preparation for the next execution
mv ~/.externaladdr ~/.previousexternaladdr
mv ~/.internaladdr ~/.previousinternaladdr
# Remove junk involved with line break fix
rm -rf ~/.linefix