-
Notifications
You must be signed in to change notification settings - Fork 1
/
archtesterd_connectivity
executable file
·184 lines (156 loc) · 3.56 KB
/
archtesterd_connectivity
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/bash
#
# Initialize ------------------------------------------------------------
#
debug=0
logfile=/var/log/archtesterd_connectivity.log
statusfile=/var/log/archtesterd_connectivity.status
resultfile=/dev/tty
#
# Functions ------------------------------------------------------------------
#
#
# Debug printouts
#
function archtester_debug {
if [ $debug = 1 ]
then
echo "archtester: debug: $*"
fi
}
#
# One round of analysis ------------------------------------------------------
#
function archtester_analyze {
archtester_debug Looking at interfaces
#
# Initialize analysis
#
v4found=0
v4publicfound=0
v6found=0
#
# Determine what interfaces we have
#
interfaces=`ifconfig -s|fgrep -v Iface|fgrep -v lo|cut -f1 -d' '`
#
# Look at each interface, and what addresses it provides
#
for interface in $interfaces
do
ifconfig $interface > /tmp/interface.$interface.data
cat /tmp/interface.$interface.data |
sed 's/inet /inet addr: /g' |
grep 'inet addr:' |
cut -f2 -d: |
sed 's/^ *//g' |
cut -f1 -d' ' > /tmp/interface.$interface.addrs.v4
cat /tmp/interface.$interface.data |
sed 's/inet6 /inet6 addr: /g' |
grep 'inet6 addr:' |
cut -f2- -d: |
sed 's/^ *//g' |
cut -f1 -d' ' > /tmp/interface.$interface.addrs.v6
cat /tmp/interface.$interface.data |
sed 's/inet6 /inet6 addr: /g' |
grep 'inet6 addr:' |
sed 's/scopeid *0x20.link./Scope: Link/g' |
sed 's/scopeid *0x0.global./Scope: Global/g' |
sed 's/scopeid *0x5/Scope: Link/g' |
sed 's/^ *//g' |
sed 's/^.*Scope://g' |
sed 's/^ *//g' |
cut -f1 -d' ' > /tmp/interface.$interface.scopes.v6
#
# Determine from the IPv4 addresses what kind of IPv4 connectivity we have
#
for a in `cat /tmp/interface.$interface.addrs.v4`
do
case $a in
10.*) v4found=1;; # RFC 1981
192.168.*) v4found=1;; # RFC 1981
172.16.*) v4found=1;; # RFC 1981
169.254.*) ;; # RFC 5731
0.0.0.0) ;; # avoid special case if not assigned
127.*) ;; # avoid localhost addresses
*.*.*.*) v4found=1;
v4publicfound=1;;
*) ;; # anything else, in case data is garbled
esac
done
#
# Determine from the IPv6 address scopes what kind of IPv6 connectivity we have
for s in `cat /tmp/interface.$interface.scopes.v6`
do
case $s in
Global) v6found=1;;
*) ;;
esac
done
done
archtester_debug V4: $v4found
archtester_debug V4 public address $v4publicfound
archtester_debug V6: $v6found
}
#
# Main program ------------------------------------------------------------
#
#
# Parse arguments
#
while [ $# -gt 0 ]
do
case x$1 in
x-debug)
shift
debug=1;;
x-quiet)
shift
debug=0;;
x-output)
shift
resultfile=$1
shift;;
*)
echo "archtesterd_connectivity: unexpected argument: $1"
exit 1;;
esac
done
archtester_analyze
count=0
if [ $v4publicfound = 1 ]
then
count=`expr $count + 1`
fi
if [ $v6found = 1 ]
then
count=`expr $count + 1`
fi
if [ $v4publicfound = 1 -o $v6found = 1 ]
then
mode=good
else
if [ $v4found = 0 ]
then
mode=search
else
mode=bad
fi
fi
echo $mode:$count > $resultfile
archtester_debug "Analysis result = $mode"
if [ -f $statusfile ]
then
prevmode=`cat $statusfile`
else
prevmode=none
fi
if [ $mode = $prevmode ]
then
nop=nop
else
date >> $logfile
echo mode=$mode v4=$v4found public=$v4publicfound v6=$v6found >> $logfile
prevmode=$mode
fi
echo $prevmode > $statusfile