-
Notifications
You must be signed in to change notification settings - Fork 0
/
wificheck.sh
executable file
·633 lines (444 loc) · 16.8 KB
/
wificheck.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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
#!/usr/bin/env bash
#############################################################################################################################################
# 2012 → 2022 - cracolinux
# 2020 - Mise à jour par j1v3_d4_v0m17 : https://github.com/j1v3/wificheck
# 2020 - Modification suite remarque par Watael : https://forum.ubuntu-fr.org/viewtopic.php?pid=22395338#p22395338
# 2022 - Modification suite à la proposition de Bruno : https://forum.ubuntu-fr.org/viewtopic.php?pid=22552050#p22552050
# 2023 - Ajout de la commande bootctl, remarque par NicoApi73 via xubu1957 : https://forum.ubuntu-fr.org/viewtopic.php?pid=22631234#p22631234
# 2024 - Refonte Astrolivier suppression des commandes obsolètes, ajout de iw, systemctl
#
# v2.1
#
# LICENCE:
#
# LICENCE PUBLIQUE RIEN À BRANLER
# Version 1, Mars 2009
# Copyright (C) 2009 Sam Hocevar
# 14 rue de Plaisance, 75014 Paris, France
#
# La copie et la distribution de copies exactes de cette licence sont
# autorisées, et toute modification est permise à condition de changer
# le nom de la licence.
#
# CONDITIONS DE COPIE, DISTRIBUTION ET MODIFICATION
# DE LA LICENCE PUBLIQUE RIEN À BRANLER
#
# 0. Faites ce que vous voulez, j’en ai RIEN À BRANLER.
#############################################################################################################################################
##uncomment for debug mode in file debug_output.txt located fin local repository
#exec 5> debug_output.txt
#BASH_XTRACEFD="5"
#PS4='$LINENO: '
#set -x
shopt -s nullglob
# Set language as enum : french = 0 ; english = 1 ; chinese = 2 . Default is french.
declare -i which_language
which_language=0
# Set as enum if wificheck prints the short output, the long output or the very long output
# short = 0 ; long = 1 ; very long = 2
declare -i which_version
which_version=0
# set as enum to print bbcode for french forum
# with bbcode = 0 ; without bbcode = 1
declare -i is_bbcode
is_bbcode=0
# variables array that store modules names for lsmod and modinfo
declare -a modules_array
# store lsmod result
declare lsmod_variable
# variable associative array used to check with command -v if a commande is installed or not. the key is the command, and the value is the package which contains the command
declare -A command_array
command_array=([uname]="coreutils" [lsb_release]="lsb-release" [lspci]="pciutils" [lshw]="lshw" [lsusb]="usbutils" [lsmod]="kmod" [dkms]="dkms" [mokutil]="mokutil" [rfkill]="rfkill" [ip]="iproute2" [ping]="iputils-ping" [resolvectl]="systemd" [ufw]="ufw" [nmcli]="network-manager" [iw]="iw" [modinfo]="kmod" [systemctl]="systemd" [iptables]="iptables" [xdg-open]="xdg-utils" [pccardctl]="pcmciautils")
# variable used with command_array
declare key
# print help on stdout with -h or bad argument
help() {
echo ""
echo "wifiCheck is a program that prints wifi info, originally created to help in the French Ubuntu forum."
echo "French is the default language in the terminal output to indicate the file location,"
echo "and BBCode is the default output for easy pasting in french forum."
echo ""
echo "USAGE:"
echo " ./wificheck.sh [options]"
echo ""
echo " -s print short version (most usefull commands), default behavior"
echo " -l print long version (more detailed)"
echo " -v print a very long version (with iw scan, iw list, plus all iptables)"
echo " -e print english version in the terminal output"
echo " -c print chinese version in the terminal output"
echo " -n doesn't print bbcode"
echo " -h print help"
echo ""
echo " More at https://github.com/olivierPrigent/wifiCheck/tree/main"
echo ""
exit 0
}
# Main function for short version
wificheck_function() {
echo "###############################################"
echo "########### Wifi Check ##################"
echo "########### $(printf '%(%Y-%m-%d)T\n' -1) ##################"
echo "###############################################"
echo -e "\n\n##### Current kernel, release, desktop ######\n"
key="uname"
if (command -v "$key") &>/dev/null ; then
local uname
uname=$(uname "-r")
echo -e " Current Kernel : ${uname} "
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
key="lsb_release"
if (command -v "$key") &>/dev/null ; then
local release
release=$(lsb_release "-d")
echo -e " Release ${release} "
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
echo " Current Desktop : $XDG_CURRENT_DESKTOP"
echo -e "\n\n################ nmcli #################\n"
key="nmcli"
if (command -v "$key") &>/dev/null ; then
nmcli | head -n -3
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
echo -e "\n\n############## iw dev ####################\n"
key="iw"
if (command -v "$key") &>/dev/null ; then
iw dev
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
echo -e "\n\n########### nmcli dev wifi ##############\n"
key="nmcli"
if (command -v "$key") &>/dev/null ; then
nmcli dev wifi
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
echo -e "\n\n################ lsusb ################\n"
key="lsusb"
if (command -v "$key") &>/dev/null ; then
lsusb
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
echo -e "\n\n####### lspci -k -nn | grep -A 3 -i net ######\n"
key="lspci"
if (command -v "$key") &>/dev/null ; then
lspci -k -nn | grep -A 3 -i net
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
echo -e "\n\n####### lsmod | grep <wifi_modules> #######\n"
key="lsmod"
if (command -v "$key") &>/dev/null ; then
lsmod_function
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
echo -e "\n\n################# dkms status ###############\n"
key="dkms"
if (command -v "$key") &>/dev/null ; then
dkms status
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
echo -e "\n\n######### mokutil --sb-state #############\n"
key="mokutil"
if (command -v "$key") &>/dev/null ; then
mokutil --sb-state
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
echo -e "\n\n########## sudo rfkill list #############\n"
key="rfkill"
if (command -v "$key") &>/dev/null ; then
sudo rfkill list
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
echo -e "\n\n################ ping no-DNS ###################\n"
key="ping"
if (command -v "$key") &>/dev/null ; then
ping -q -c1 -w1 $(find_my_gateway) &>/dev/null && echo "ping gateway ipv4 : ok" || echo "ping gateway ipv4 : bad !"
ping6 -q -c1 -w1 $(find_my_gateway) &>/dev/null && echo "ping gateway ipv6 : ok" || echo "ping gateway ipv6 : bad !"
ping -4 -q -c1 -w1 1.0.0.1 &>/dev/null && echo "ping cloudflare ipv4 : ok" || echo "ping cloudflare ipv4 : bad !"
ping -6 -q -c1 -w1 2606:4700:4700::1001 &>/dev/null && echo "ping cloudflare ipv6 : ok" || echo "ping cloudflare ipv6 : bad !"
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
echo -e "\n\n########### sudo ufw status #############\n"
key="ufw"
if (command -v "$key") &>/dev/null ; then
sudo ufw status
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
}
long_function() {
echo -e "\n\n######### resolvectl | grep Server #########\n"
key="resolvectl"
if (command -v "$key") &>/dev/null ; then
resolvectl | grep Server
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
echo -e "\n\n###### cat /etc/network/interfaces #######"
case ${which_language} in
0)
echo -e "# ce fichier est obsolète sauf si vous savez ce que vous faîtes #\n"
;;
1)
echo -e "## this file is deprecated except if you know what you're doing ##\n"
;;
2)
echo -e "###### 该文件已弃用,除非您知道自己在做什么 #######"
;;
esac
cat /etc/network/interfaces
echo -e "\n\n######## sudo lshw -C network #########\n"
key="lshw"
if (command -v "$key") &>/dev/null ; then
sudo lshw -C network
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
echo -e "\n\n######## PCMCIA card info #############\n\n"
key="pccardctl"
if (command -v "$key") &>/dev/null; then
pccardctl info
else
echo "'pccardctl' is not installed (package \"pcmciautils\")."
fi
echo -e "\n\n################ ip a ###################\n"
key="ip"
if (command -v "$key") &>/dev/null ; then
ip a
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
echo -e "\n\n####### modinfo <wifi_modules> |grep parm #######\n"
key="modinfo"
if (command -v "$key") &>/dev/null ; then
for module in ${modules_array[@]} ; do
echo -e "\n Modules parm for ${module} :"
modinfo ${module} |grep parm
done
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
echo -e "\n\n####### systemctl list network units #########\n"
key="systemctl"
if (command -v "$key") &>/dev/null ; then
systemctl list-units --type=service --all |grep -iE 'network|wpa'
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
echo -e "\n\n######## nmcli connection show ###########\n"
key="nmcli"
if (command -v "$key") &>/dev/null ; then
nmcli connection show 2>/dev/null
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
}
# For long argument. Adds iw and nmcli commands that needs interface name. Goes in a for loop in case there are several interfaces.
interfaces_long_function() {
echo -e "\n\n######### nmcli -f all d show $interface #############\n"
key="nmcli"
if (command -v "$key") &>/dev/null ; then
nmcli -f all d show $interface
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
echo -e "\n\n######### iw dev $interface link #############\n"
key="iw"
if (command -v "$key") &>/dev/null ; then
iw dev $interface link
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
}
### For very long argument. Goes in a for loop in case there are several interfaces.
very_long_function() {
key="iptables"
if (command -v "$key") &>/dev/null ; then
echo -e "\n\n#### iptables -vL -t filter|nat|mangle|raw|security #####\n"
echo "\n ### table filter ###"
sudo iptables -vL -t filter
echo "\n ### table nat ###"
sudo iptables -vL -t nat
echo "\n ### table mangle ###"
sudo iptables -vL -t mangle
echo "\n ### table raw ###"
sudo iptables -vL -t raw
echo "\n ### table security ###"
sudo iptables -vL -t security
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
echo -e "\n\n######## iw list ###########\n"
key="iw"
if (command -v "$key") &>/dev/null ; then
iw list
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
}
## For very long argument. Goes in a for loop in case there are several interfaces.
interfaces_very_long_function() {
echo -e "\n\n######## iw dev $interface station dump ###########\n"
key="iw"
if (command -v "$key") &>/dev/null ; then
iw dev $interface station dump
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
echo -e "\n\n############ iw dev $interface scan ############\n"
key="iw"
if (command -v "$key") &>/dev/null ; then
sudo iw dev $interface scan
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi
}
## find the modules that use cfg80211, find modules that use those modules,
## print the lsmod of all these modules, sort only one instace
lsmod_function() {
modules_array=("cfg80211")
lsmod_variable=$(lsmod)
readarray -t -d "," -O"${#modules_array[@]}" modules_array <<< ${lsmod_variable} | awk '{if ($1 == "cfg80211") print $4}'
for i in "${!modules_array[@]}" ; do
readarray -t -O "${#modules_array[@]}" modules_array < <(echo "${lsmod_variable}" | grep "${modules_array[$i]}" | awk '{split($4, a, ","); for (i in a) print a[i]}')
done
for i in "${!modules_array[@]}" ; do
readarray -t -O "${#modules_array[@]}" modules_array < <(echo "${lsmod_variable}" | grep "${modules_array[$i]}" | awk '{split($4, a, ","); for (i in a) print a[i]}')
done
readarray -t modules_array < <(printf "%s\n" "${modules_array[@]}" |sort -u)
for i in "${!modules_array[@]}" ; do
readarray -t -O "${#modules_array[@]}" modules_array < <(echo "${lsmod_variable}" | grep "${modules_array[$i]}" | awk '{split($4, a, ","); for (i in a) print a[i]}')
done
readarray -t modules_array < <(printf "%s\n" "${modules_array[@]}" |sort -u)
echo "Module Size Used by"
length=${#modules_array[@]}
for (( j=0; j<length; j++ )); do
printf "%s\n" echo "$lsmod_variable" | awk -v word="${modules_array[$j]}" '$1 == word { print }'
done
}
### function for ping printing in wificheck_function
find_my_gateway() {
ip route show default | cut -d" " -f3
}
###### print on terminal at the end
french_terminal_output() {
echo "####################################################################"
echo "Le fichier wificheck.log a été crée dans "$HOME""
echo "Vous n'avez plus qu'à copier/coller son contenu entier sur le forum"
echo " accès →→ "$HOME"/wificheck.log"
echo "####################################################################"
}
english_terminal_output() {
echo "####################################################################"
echo "File wificheck.log has been created in "$HOME""
echo "You simply have to copy/paste the entire content on the forum"
echo "Markup is bbcode for french ubuntu forum"
echo " acces →→ "$HOME"/wificheck.log"
echo "####################################################################"
}
chinese_terminal_output() {
echo "####################################################################"
echo "wificheck.log 文件已创建在 "$HOME""
echo "你只需将整个内容复制/粘贴到论坛上"
echo "标记语言是法国Ubuntu论坛的BBCode"
echo " 访问 →→ "$HOME"/wificheck.log"
echo "####################################################################"
}
######################################################
################ main ############################
## check for arguments and set variable
while getopts "hslecnv" arg; do
case $arg in
l)
which_version=1
;;
s)
which_version=0
;;
v)
which_version=2
;;
e)
which_language=1
;;
c)
which_language=2
;;
n)
is_bbcode=1
;;
h)
help
;;
\?)
echo "Invalid option: -$OPTARG"
help
;;
esac
done
## print stderr and stdout in file
exec 3>&1
exec &>~/wificheck.log
## chech if we print bbcode
if [[ ${is_bbcode} -eq 0 ]]; then
echo "[code]"
fi
wificheck_function
## check if we add long version
if [[ ${which_version} -eq 1 ]]; then
long_function
for interface in /sys/class/net/w[lw]*; do
interface=${interface##*/}
interfaces_long_function
done
fi
## check if we add very long version
if [[ ${which_version} -eq 2 ]]; then
long_function
for interface in /sys/class/net/w[lw]*; do
interface=${interface##*/}
interfaces_long_function
done
very_long_function
for interface in /sys/class/net/w[lw]*; do
interface=${interface##*/}
interfaces_very_long_function
done
fi
## chech if we print bbcode
if [[ ${is_bbcode} -eq 0 ]]; then
echo "[/code]"
fi
## Print back on terminal for the file location
exec >&3-
## check which language to print the file location
case ${which_language} in
0)
french_terminal_output
;;
1)
english_terminal_output
;;
2)
chinese_terminal_output
;;
esac
## open graphical text editor and print nothing on terminal (otherwise terminal won't close)
key="xdg-open"
if (command -v "$key") &>/dev/null ; then
xdg-open ~/wificheck.log 1>/dev/null 2>&1
else
echo "command $key is not present you should install ${command_array[$key]} package"
fi