-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnet-test.sh
300 lines (275 loc) · 19.6 KB
/
net-test.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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/usr/bin/env bash
# Keeping it portable.
# see: https://www.cyberciti.biz/tips/finding-bash-perl-python-portably-using-env.html
echo " "
echo "╔═══════════════════════════════════════════════════════════════════════╗"
echo "║ Linux Network Diagnostic and Testing tool ║"
echo "║ © 2021 Kevin Karhan [email protected] ║"
echo "║ made for Compay https://www.compay.de/ ║"
echo "║ licensed under GPLv3 ║"
echo "╠═══════════════════════════════════════════════════════════════════════╣"
echo "║ USE ON YOUR OWN RISK! THE AUTHOR IS NOT LIABLE FOR ANY DAMAGES! ║"
echo "╟───────────────────────────────────────────────────────────────────────╢"
echo "║ The tool is provided >> as - is << without any warranties whatsoever! ║"
echo "╚═══════════════════════════════════════════════════════════════════════╝"
echo " "
# obligational header
echo " "
echo "═════════════════════════════════════════════════════════════════════════"
echo "Starting logfile..."
echo "═════════════════════════════════════════════════════════════════════════"
echo " "
touch $HOME/net-analysis.log
# creating logfile
{
# Creating the log
# see: https://unix.stackexchange.com/questions/61931/redirect-all-subsequent-commands-stderr-using-exec/61932#61932
echo " "
echo "═════════════════════════════════════════════════════════════════════════"
echo "logging started..."
echo "─────────────────────────────────────────────────────────────────────────"
date
# record date & time of start
echo "═════════════════════════════════════════════════════════════════════════"
echo " "
echo "collecting basic system data..."
echo " "
screenfetch
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
hostname
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
hostname -A
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
hostname -a
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
hostname -f
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
hostname -i
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
hostname -I
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
hostname -y
# checking detailed info on the system, with fallbacks in case screenfetch is not installed and/or to find different settings
echo " "
echo "═════════════════════════════════════════════════════════════════════════"
echo " "
echo "═════════════════════════════════════════════════════════════════════════"
echo "Collecting interface data..."
echo " "
ifconfig
# ifconfig for the network interfaces
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
nmcli connection show
# list active connections
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
nmcli device show
# list devices
echo " "
echo "═════════════════════════════════════════════════════════════════════════"
echo "determining public IP adresses..."
curl ipinfo.io/ip
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
wget -qO- ipinfo.io/ip
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
lynx -source ipinfo.io/ip
# determine public IP adress
# see: https://stackoverflow.com/questions/14594151/methods-to-detect-public-ip-address-in-bash#14594304
echo " "
echo "═════════════════════════════════════════════════════════════════════════"
echo "collecting network statistics..."
echo "─────────────────────────────────────────────────────────────────────────"
echo "...interfaces..."
netstat -i
echo "─────────────────────────────────────────────────────────────────────────"
echo "...routes..."
netstat -p -W -r
echo "─────────────────────────────────────────────────────────────────────────"
echo "...multicast groups..."
netstat -g
echo "─────────────────────────────────────────────────────────────────────────"
echo "...statistics..."
netstat -s
echo "─────────────────────────────────────────────────────────────────────────"
echo "...listening sockets"
netstat -p -W -N -e -o -l
# this should provide info on existing/open connections of the user.
echo "═════════════════════════════════════════════════════════════════════════"
echo " "
echo "Running speedtests..."
echo "1/2"
echo " "
speedtest -v -s 32412 -b -P 8 -p no
# This will add additional info and make the test repeatable in the first run.
# Hardcoded server "3585" is from Leaseweb, located in Frankfurt a.M., Germany.
echo "─────────────────────────────────────────────────────────────────────────"
echo "2/2"
echo " "
speedtest -vv -b -p no
# This will ran another test using the "closest" server by ping.
echo "─────────────────────────────────────────────────────────────────────────"
echo "checking proximity speedtesting servers"
echo " "
speedtest -L
# OFC one could subsidize the proprietary Ookla Speedtest CLI [https://www.speedtest.net/apps/cli]
# with the Librespeed CLI [https://github.com/librespeed/speedtest-cli],
# This would certainly add value to the project
# If one is interested to do so, feel free to do it & let me know about it!
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
echo "pinging popular public DNS servers..."
echo "─────────────────────────────────────────────────────────────────────────"
echo "Google"
ping 8.8.8.8 -c 1 -D
# Google DNS
echo "─────────────────────────────────────────────────────────────────────────"
echo "Cloudflare"
ping 1.1.1.1 -c 1 -D
# Cloudflare DNS
echo "─────────────────────────────────────────────────────────────────────────"
echo "Quad9"
ping 9.9.9.9 -c 1 -D
# Quad9 DNS
# It may be intentional [or not] to have these fail.
# Espechally when the network is configured to ban other DNS servers except the internal one for security reasons.
echo "═════════════════════════════════════════════════════════════════════════"
echo " "
y
echo "pinging obscure DNS Servers..."
echo "─────────────────────────────────────────────────────────────────────────"
echo "OpenNIC"
ping 94.16.114.254 -c 1 -D
ping 2a03:4000:28:365::1 -c 1 -D
# OpenNIC Server: https://servers.opennic.org/edit.php?srv=ns9.de.dns.opennic.glue
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
ping ns1.fische.io -c 1 -D
# OpenNIC Server: https://servers.opennic.org/edit.php?srv=ns21.de.dns.opennic.glue
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
ping 94.103.153.176 -c 1 -D
ping 2a02:990:219:1:ba:1337:cafe:3 -c 1 -D
# OpenNIC Server: https://servers.opennic.org/edit.php?srv=ns5.opennic.glue
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
ping okashi.me -c 1 -D
# OpenNIC Server: https://servers.opennic.org/edit.php?srv=ns13.opennic.glue
echo "═════════════════════════════════════════════════════════════════════════"
echo "name.space"
ping 72.69.161.7 -c 1 -D
ping 72.69.161.13 -c 1 -D
# Name.speace Servers: http://namespace.us/opt-in.php
echo "═════════════════════════════════════════════════════════════════════════"
# It may be intentional [or not] to have these fail.
# Espechally when the network is configured to ban other DNS servers except the internal one for security reasons.
echo " "
echo "pinging internal IPv4's"
echo "─────────────────────────────────────────────────────────────────────────"
ping 192.168.0.1 -c 1 -D
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
ping 192.168.1.1 -c 1 -D
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
ping 172.16.0.1 -c 1 -D
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
ping 10.0.0.1 -c 1 -D
# RFC 1918 Adress spaces
# See: https://en.wikipedia.org/wiki/Private_network
echo "─────────────────────────────────────────────────────────────────────────"
ping 100.64.0.1 -c 1 -D
# CGNAT
# Failing this test is normal and should not yield any result, even if your provider uses CGNAT
# See: https://en.wikipedia.org/wiki/Carrier-grade_NAT
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
echo "testing public hostnames"
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
nslookup google.de
ping google.de -c 1 -D
# Google.de
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
nslookup bsi.bund.de
ping bsi.bund.de -c 1 -D
# BSI
echo "═════════════════════════════════════════════════════════════════════════"
echo " "
echo "DNS lookup of timeservers"
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
nslookup ptbtime1.ptb.de
ping ptbtime1.ptb.de -c 1 -D
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
nslookup ptbtime2.ptb.de
ping ptbtime2.ptb.de -c 1 -D
echo " "
echo "─────────────────────────────────────────────────────────────────────────"
echo " "
nslookup ptbtime3.ptb.de
ping ptbtime3.ptb.de -c 1 -D
# PTB Timeservers
# See: https://www.ptb.de/cms/en/ptb/fachabteilungen/abtq/gruppe-q4/ref-q42/time-synchronization-of-computers-using-the-network-time-protocol-ntp.html
echo "═════════════════════════════════════════════════════════════════════════"
echo "testing completed!"
echo " "
date
# record date & time of end
echo "═════════════════════════════════════════════════════════════════════════"
} 2>&1 | tee $HOME/net-analysis.log
# exiting the log
echo " "
echo "logfile created!"
echo " "
clear
# clearing screen
echo " "
echo "╔═══════════════════════════════════════════════════════════════════════╗"
echo "║ Tests competed! ║"
echo "╟───────────────────────────────────────────────────────────────────────╢"
echo "║ Please send the now opening email and an admin will contact you ASAP! ║"
echo "╚═══════════════════════════════════════════════════════════════════════╝"
echo " "
# final screen
thunderbird -compose "attachment='$HOME/net-analysis.log',to=administrator@localhost,subject=network-diagnostic-test,format=2,body=this is an automated network test"
# hardcoded email adress & message s well as attachments.
# ADAPT BEFORE USING!
# since thunderbird is being used per default, this should work out of the gate, only requiring a user to press "send".
# see: http://kb.mozillazine.org/Command_line_arguments_%28Thunderbird%29 & https://stackoverflow.com/questions/27836576/adding-several-attachments-to-thunderbird-from-command-line/28002815#28002815
exit
# closes the script