]> git.saurik.com Git - apple/configd.git/blob - get-network-info
configd-1061.141.1.tar.gz
[apple/configd.git] / get-network-info
1 #!/bin/sh
2
3 #
4 # Copyright © 2015-2020 Apple Inc.
5 #
6 # get-network-info
7 #
8 # Collect network information.
9 #
10
11 PATH=/bin:/usr/bin:/sbin:/usr/sbin
12
13 # __SETUP_ROUTINES_BEGIN__
14
15 process_opts () {
16
17 for i in $ARGS
18 do
19 case "$i" in
20 -c)
21 COLLECT_CONFIGURATION_FILES="Y"
22 shift
23 ;;
24 -n)
25 COLLECT_NDF_INFO="Y"
26 shift
27 ;;
28 -P)
29 COLLECT_PCAP="N"
30 shift
31 ;;
32 -s)
33 COLLECT_SENSITIVE_INFO="Y"
34 shift
35 ;;
36 --)
37 shift
38 ;;
39 *)
40 REQUESTED_OUTDIR="${i}"
41 shift
42 ;;
43 esac
44 done
45
46 }
47
48 set_root () {
49
50 PRIV=""
51 if [ ${EUID} -ne 0 ]; then
52 PRIV="sudo"
53 fi
54
55 }
56
57 #
58 # Setup
59 #
60 setup () {
61
62 set_root
63 umask 077
64 cd "${REQUESTED_OUTDIR}"
65
66 }
67
68 # __SETUP_ROUTINES_END__
69
70
71 # __COMMAND_ROUTINES_BEGIN__
72
73 #
74 # mDNSResponder state dump
75 # /usr/bin/dns-sd -O -stdout will print the state of mDNSResponder to STDOUT
76 #
77 collect_state_dump_sensitive () {
78
79 echo "`date +"%Y-%m-%d %H:%M:%S"`: collect_state_dump_sensitive" >> get-network-info.txt
80 ${PRIV} /usr/bin/dns-sd -O -stdout > mDNSResponder_state_dump.txt 2>&1
81
82 }
83
84 #
85 # network interface configuration
86 #
87 run_ifconfig () {
88
89 if [ ! -x /sbin/ifconfig ]; then
90 return
91 fi
92
93 echo "`date +"%Y-%m-%d %H:%M:%S"`: run_ifconfig" >> get-network-info.txt
94 /sbin/ifconfig -a -L -b -m -r -v -v > ifconfig.txt 2>&1
95 if [ $? -ne 0 ]; then
96 /sbin/ifconfig -a > ifconfig.txt 2>&1
97 fi
98
99 }
100
101 #
102 # network route configuration and statistics
103 #
104 run_netstat () {
105
106 if [ ! -x /usr/sbin/netstat ]; then
107 return
108 fi
109
110 echo "`date +"%Y-%m-%d %H:%M:%S"`: run_netstat" >> get-network-info.txt
111 echo "#" > netstat.txt
112 echo "# netstat -n -r -a -l" >> netstat.txt
113 echo "#" >> netstat.txt
114 /usr/sbin/netstat -n -r -a -l >> netstat.txt 2>&1
115
116 echo "#" >> netstat.txt
117 echo "# netstat -A -a -l -n -v -W" >> netstat.txt
118 echo "#" >> netstat.txt
119 /usr/sbin/netstat -A -a -l -n -v -W >> netstat.txt 2>&1
120
121 echo "#" >> netstat.txt
122 echo "# netstat -s" >> netstat.txt
123 echo "#" >> netstat.txt
124 /usr/sbin/netstat -s >> netstat.txt 2>&1
125
126 echo "#" >> netstat.txt
127 echo "# netstat -rs" >> netstat.txt
128 echo "#" >> netstat.txt
129 /usr/sbin/netstat -rs >> netstat.txt 2>&1
130
131 echo "#" >> netstat.txt
132 echo "# netstat -mmm" >> netstat.txt
133 echo "#" >> netstat.txt
134 /usr/sbin/netstat -mmm >> netstat.txt 2>&1
135
136 echo "#" >> netstat.txt
137 echo "# netstat -i -n -d" >> netstat.txt
138 echo "#" >> netstat.txt
139 /usr/sbin/netstat -i -n -d >> netstat.txt 2>&1
140
141 echo "#" >> netstat.txt
142 echo "# netstat -i -x R" >> netstat.txt
143 echo "#" >> netstat.txt
144 /usr/sbin/netstat -i -x R >> netstat.txt 2>&1
145
146 echo "#" >> netstat.txt
147 echo "# netstat -a -n -p mptcp" >> netstat.txt
148 echo "#" >> netstat.txt
149 /usr/sbin/netstat -anp mptcp >> netstat.txt 2>&1
150
151 echo "#" >> netstat.txt
152 echo "# netstat -s -p mptcp" >> netstat.txt
153 echo "#" >> netstat.txt
154 /usr/sbin/netstat -s -p mptcp >> netstat.txt 2>&1
155
156 echo "#" >> netstat.txt
157 echo "# netstat -g -n -s" >> netstat.txt
158 echo "#" >> netstat.txt
159 /usr/sbin/netstat -g -n -s >> netstat.txt 2>&1
160
161 if [ -x /sbin/ifconfig ]; then
162 for if in ${IF_LIST}
163 do
164 echo "#" >> netstat.txt
165 echo "# netstat -s -I ${if}" >> netstat.txt
166 echo "#" >> netstat.txt
167 /usr/sbin/netstat -s -I ${if} >> netstat.txt 2>&1
168
169 IF_INFO=`/sbin/ifconfig -v ${if}`
170 `echo $IF_INFO | grep -q TXSTART`
171 if [ $? -eq 0 ]; then
172 echo "#" >> netstat.txt
173 echo "# netstat -qq -I ${if}" >> netstat.txt
174 echo "#" >> netstat.txt
175 /usr/sbin/netstat -qq -I ${if} >> netstat.txt 2>&1
176 fi
177
178 `echo $IF_INFO | grep -q RXPOLL`
179 if [ $? -eq 0 ]; then
180 echo "#" >> netstat.txt
181 echo "# netstat -Q -I ${if}" >> netstat.txt
182 echo "#" >> netstat.txt
183 /usr/sbin/netstat -Q -I ${if} >> netstat.txt 2>&1
184 fi
185 done
186 fi
187
188 }
189
190 #
191 # ndp
192 #
193 run_ndp () {
194
195 if [ ! -x /usr/sbin/ndp ]; then
196 return
197 fi
198
199 echo "`date +"%Y-%m-%d %H:%M:%S"`: run_ndp" >> get-network-info.txt
200 echo "#" > ndp-info.txt
201 echo "# ndp -n -a" >> ndp-info.txt
202 echo "#" >> ndp-info.txt
203 /usr/sbin/ndp -n -a >> ndp-info.txt 2>&1
204
205 echo "#" >> ndp-info.txt
206 echo "# ndp -n -p" >> ndp-info.txt
207 echo "#" >> ndp-info.txt
208 /usr/sbin/ndp -n -p >> ndp-info.txt 2>&1
209
210 echo "#" >> ndp-info.txt
211 echo "# ndp -n -r" >> ndp-info.txt
212 echo "#" >> ndp-info.txt
213 /usr/sbin/ndp -n -r >> ndp-info.txt 2>&1
214
215 if [ -x /sbin/ifconfig ]; then
216 for if in ${IF_LIST}
217 do
218 echo "#" >> ndp-info.txt
219 echo "# ndp -i ${if}" >> ndp-info.txt
220 echo "#" >> ndp-info.txt
221 /usr/sbin/ndp -i ${if} >> ndp-info.txt 2>&1
222 done
223 fi
224
225 }
226
227 #
228 # arp
229 #
230 run_arp () {
231
232 if [ ! -x /usr/sbin/arp ]; then
233 return
234 fi
235
236 echo "`date +"%Y-%m-%d %H:%M:%S"`: run_arp" >> get-network-info.txt
237 echo "#" > arp-info.txt
238 echo "# arp -n -a" >> arp-info.txt
239 echo "#" >> arp-info.txt
240 /usr/sbin/arp -n -a >> arp-info.txt 2>&1
241
242 }
243
244 #
245 # DHCP configuration
246 #
247 run_ipconfig () {
248
249 if [ ! -x /usr/sbin/ipconfig ]; then
250 return
251 fi
252
253 echo "`date +"%Y-%m-%d %H:%M:%S"`: run_ipconfig" >> get-network-info.txt
254 for if in ${IF_LIST}
255 do
256 case ${if} in
257 lo* )
258 ;;
259 *)
260 echo "#" >> ipconfig-info.txt
261 echo "# INTERFACE ${if}" >> ipconfig-info.txt
262 echo "#" >> ipconfig-info.txt
263
264 echo "DHCPv4 information:" >> ipconfig-info.txt
265
266 IPCONFIG_INFO=`/usr/sbin/ipconfig getpacket ${if}`
267 if [ "${IPCONFIG_INFO}" != "" ]; then
268 echo "${IPCONFIG_INFO}" >> ipconfig-info.txt
269 else
270 echo "not available" >> ipconfig-info.txt
271 fi
272
273 echo"" >> ipconfig-info.txt
274
275 echo "DHCPv6 information:" >> ipconfig-info.txt
276
277 IPCONFIG_INFO=`/usr/sbin/ipconfig getv6packet ${if}`
278 if [ "${IPCONFIG_INFO}" != "" ]; then
279 echo "${IPCONFIG_INFO}" >> ipconfig-info.txt
280 else
281 echo "not available" >> ipconfig-info.txt
282 fi
283
284 echo"" >> ipconfig-info.txt
285 ;;
286 esac
287 done
288
289 }
290
291 #
292 # IPsec configuration
293 #
294 run_setkey () {
295
296 if [ ! -x /usr/sbin/setkey -o ! -x /usr/bin/perl ]; then
297 return
298 fi
299
300 echo "`date +"%Y-%m-%d %H:%M:%S"`: run_setkey" >> get-network-info.txt
301 echo "#" > ipsec.txt
302 echo "# setkey -D" >> ipsec.txt
303 echo "#" >> ipsec.txt
304 ${PRIV} /usr/sbin/setkey -D \
305 | /usr/bin/perl -l -n -e '
306 if (/^(\s+[AE]:\s+\S+\s+)"?(.*)"?\s*$/) {
307 printf "%s[redacted]%s\n", $1, $3;
308 } else {
309 printf "%s\n", $_;
310 }
311 ' >> ipsec.txt
312
313 echo "" >> ipsec.txt
314 echo "#" >> ipsec.txt
315 echo "# setkey -Pp -D" >> ipsec.txt
316 echo "#" >> ipsec.txt
317 ${PRIV} /usr/sbin/setkey -Pp -D >> ipsec.txt
318
319 for CF in /var/run/racoon/*.conf
320 do
321 if [ ! -r "${CF}" ]; then
322 continue
323 fi
324
325 echo "" >> ipsec.txt
326 echo "#" >> ipsec.txt
327 echo "# ${CF}" >> ipsec.txt
328 echo "#" >> ipsec.txt
329 ${PRIV} cat ${CF} \
330 | /usr/bin/perl -l -n -e '
331 if (/^(\s+shared_secret\s+use\s+)"?([^\s;"]+)"?(.*)/) {
332 printf "%s[redacted]%s\n", $1, $3;
333 } else {
334 printf "%s\n", $_;
335 }
336 ' >> ipsec.txt
337 done
338
339 }
340
341 #
342 # skywalk configuration and statistics
343 #
344 run_skywalk () {
345
346 if [ ! -x /usr/sbin/skywalkctl ]; then
347 return
348 fi
349
350 echo "`date +"%Y-%m-%d %H:%M:%S"`: run_skywalk" >> get-network-info.txt
351 echo "#" > skywalk.txt
352 echo "# skywalkctl show" >> skywalk.txt
353 echo "#" >> skywalk.txt
354 /usr/sbin/skywalkctl show >> skywalk.txt 2>&1
355
356 echo "#" >> skywalk.txt
357 echo "# skywalkctl flow -n" >> skywalk.txt
358 echo "#" >> skywalk.txt
359 /usr/sbin/skywalkctl flow -n >> skywalk.txt 2>&1
360
361 echo "#" >> skywalk.txt
362 echo "# skywalkctl flow-route -n" >> skywalk.txt
363 echo "#" >> skywalk.txt
364 /usr/sbin/skywalkctl flow-route -n >> skywalk.txt 2>&1
365
366 echo "#" >> skywalk.txt
367 echo "# skywalkctl flow-switch" >> skywalk.txt
368 echo "#" >> skywalk.txt
369 /usr/sbin/skywalkctl flow-switch >> skywalk.txt 2>&1
370
371 echo "#" >> skywalk.txt
372 echo "# skywalkctl flow-owner" >> skywalk.txt
373 echo "#" >> skywalk.txt
374 /usr/sbin/skywalkctl flow-owner >> skywalk.txt 2>&1
375
376 echo "#" >> skywalk.txt
377 echo "# skywalkctl flow-adv" >> skywalk.txt
378 echo "#" >> skywalk.txt
379 /usr/sbin/skywalkctl flow-adv >> skywalk.txt 2>&1
380
381 echo "#" >> skywalk.txt
382 echo "# skywalkctl netstat -s" >> skywalk.txt
383 echo "#" >> skywalk.txt
384 /usr/sbin/skywalkctl netstat -s >> skywalk.txt 2>&1
385
386 echo "#" >> skywalk.txt
387 echo "# skywalkctl netstat -s --global" >> skywalk.txt
388 echo "#" >> skywalk.txt
389 /usr/sbin/skywalkctl netstat -s --global >> skywalk.txt 2>&1
390
391 echo "#" >> skywalk.txt
392 echo "# skywalkctl interface" >> skywalk.txt
393 echo "#" >> skywalk.txt
394 /usr/sbin/skywalkctl interface >> skywalk.txt 2>&1
395
396 echo "#" >> skywalk.txt
397 echo "# skywalkctl channel" >> skywalk.txt
398 echo "#" >> skywalk.txt
399 /usr/sbin/skywalkctl channel >> skywalk.txt 2>&1
400
401 echo "#" >> skywalk.txt
402 echo "# skywalkctl provider -D" >> skywalk.txt
403 echo "#" >> skywalk.txt
404 /usr/sbin/skywalkctl provider -D >> skywalk.txt 2>&1
405
406 echo "#" >> skywalk.txt
407 echo "# skywalkctl netns -a" >> skywalk.txt
408 echo "#" >> skywalk.txt
409 /usr/sbin/skywalkctl netns -a >> skywalk.txt 2>&1
410
411 echo "#" >> skywalk.txt
412 echo "# skywalkctl memory" >> skywalk.txt
413 echo "#" >> skywalk.txt
414 /usr/sbin/skywalkctl memory >> skywalk.txt 2>&1
415
416 }
417
418 #
419 # skywalk configuration and statistics
420 #
421 run_nettop () {
422
423 if [ ! -x /usr/bin/nettop ]; then
424 return
425 fi
426
427 echo "`date +"%Y-%m-%d %H:%M:%S"`: run_nettop" >> get-network-info.txt
428 echo "#" > nettop.txt
429 echo "# nettop -n -l 1" >> nettop.txt
430 echo "#" >> nettop.txt
431 /usr/bin/nettop -n -l 1 >> nettop.txt 2>&1
432
433 }
434
435 #
436 # Network preferences
437 #
438 collect_configuration_files () {
439
440 echo "`date +"%Y-%m-%d %H:%M:%S"`: collect_configuration_files" >> get-network-info.txt
441 for f in \
442 /Library/Preferences/com.apple.networkextension.plist \
443 /Library/Preferences/com.apple.networkextension.control.plist \
444 /Library/Preferences/com.apple.networkextension.necp.plist \
445 /Library/Preferences/com.apple.networkextension.cache.plist \
446 /Library/Preferences/com.apple.networkextension.uuidcache.plist \
447 /Library/Preferences/SystemConfiguration/com.apple.nat.plist \
448 /Library/Preferences/SystemConfiguration/com.apple.RemoteAccessServers.plist \
449 /Library/Preferences/SystemConfiguration/com.apple.smb.server.plist \
450 /Library/Preferences/com.apple.mDNSResponder.plist \
451 /Library/Preferences/SystemConfiguration/NetworkInterfaces.plist \
452 /Library/Preferences/SystemConfiguration/preferences.plist \
453
454 do
455 if [ -e "${f}" ]; then
456 b="`basename ${f}`"
457 cat "${f}" > "${b}" 2>&1
458 fi
459 done
460
461 if [ -e /etc/resolv.conf ]; then
462 cat /etc/resolv.conf > etc-resolv-conf.txt 2>&1
463 fi
464 if [ -e /var/run/resolv.conf ]; then
465 cat /var/run/resolv.conf > var-run-resolv-conf.txt 2>&1
466 fi
467 if [ -e /etc/resolver ]; then
468 tar -c -H /etc/resolver > etc-resolver.tar 2>/dev/null
469 elif [ -e /Library/Preferences/SystemConfiguration/resolver ]; then
470 tar -c -H /Library/Preferences/SystemConfiguration/resolver > LPS-resolver.tar 2>/dev/null
471 fi
472
473 MIGRATION_FILES=$(/bin/ls -1 \
474 /Library/Preferences/SystemConfiguration/preferences-pre-*.plist \
475 /Library/Preferences/SystemConfiguration/NetworkInterfaces-pre-*.plist \
476 2>/dev/null)
477 if [ -n "${MIGRATION_FILES}" ]; then
478 MIGRATION_FILES+=" /Library/Preferences/SystemConfiguration/preferences.plist"
479 MIGRATION_FILES+=" /Library/Preferences/SystemConfiguration/NetworkInterfaces.plist"
480 tar -c -H ${MIGRATION_FILES} > migration.tar 2>/dev/null
481 fi
482 }
483
484 #
485 # VPN
486 #
487 collect_vpn_logs () {
488
489 echo "`date +"%Y-%m-%d %H:%M:%S"`: collect_vpn_logs" >> get-network-info.txt
490 for f in \
491 /var/log/vpnd.log \
492 /var/log/racoon.log \
493
494 do
495 if [ -e "${f}" ]; then
496 b="`basename ${f}`"
497 ${PRIV} cat "${f}" > "${b}".txt 2>&1
498 fi
499 done
500 }
501
502 #
503 # Policy
504 #
505 run_neutil () {
506
507 if [ ! -x /usr/local/bin/neutil ]; then
508 return
509 fi
510
511 echo "`date +"%Y-%m-%d %H:%M:%S"`: run_neutil" >> get-network-info.txt
512 (
513 echo "#" > necp.txt
514 echo "# neutil policy dump" >> necp.txt
515 echo "#" >> necp.txt
516 /usr/local/bin/neutil policy dump >> necp.txt 2>&1
517
518 echo "#" > network-agents.txt
519 echo "# neutil agent dump" >> network-agents.txt
520 echo "#" >> network-agents.txt
521 /usr/local/bin/neutil agent dump >> network-agents.txt 2>&1
522
523 # Generates a default-level log message containing the current file handles that UserEventAgent has
524 /usr/local/bin/neutil session log-file-handles
525 sleep 1 &
526 ) &
527 }
528
529 #
530 # Path
531 #
532 run_network_test () {
533
534 if [ ! -x /usr/local/bin/network_test ]; then
535 return
536 fi
537
538 echo "`date +"%Y-%m-%d %H:%M:%S"`: run_network_test" >> get-network-info.txt
539 /usr/local/bin/network_test path_watcher -dump > nw_path.txt 2>&1
540
541 }
542
543 #
544 # Network, DNS, Proxy, Reachability, Cache information
545 #
546 run_scutil () {
547
548 if [ ! -x /usr/sbin/scutil ]; then
549 return
550 fi
551
552 echo "`date +"%Y-%m-%d %H:%M:%S"`: run_scutil" >> get-network-info.txt
553 echo "#" > network-information.txt
554 echo "# scutil -d -v --nwi" >> network-information.txt
555 echo "#" >> network-information.txt
556 /usr/sbin/scutil -d -v --nwi >> network-information.txt 2>&1
557 for if in ${IF_LIST}
558 do
559 echo "" >> network-information.txt
560 echo "#" >> network-information.txt
561 echo "# scutil --nwi ${if}" >> network-information.txt
562 echo "#" >> network-information.txt
563 scutil --nwi ${if} >> network-information.txt 2>&1
564 done
565
566 echo "#" > dns-configuration.txt
567 echo "# scutil -d -v --dns" >> dns-configuration.txt
568 echo "#" >> dns-configuration.txt
569 /usr/sbin/scutil -d -v --dns >> dns-configuration.txt 2>&1
570
571 echo "#" > proxy-configuration.txt
572 echo "# scutil -d -v --proxy" >> proxy-configuration.txt
573 echo "#" >> proxy-configuration.txt
574 /usr/sbin/scutil -d -v --proxy >> proxy-configuration.txt 2>&1
575
576 echo "#" > reachability-info.txt
577 echo '# scutil -d -v -r www.apple.com' >> reachability-info.txt
578 echo "#" >> reachability-info.txt
579 /usr/sbin/scutil -d -v -r www.apple.com >> reachability-info.txt 2>&1
580
581 echo "#" >> reachability-info.txt
582 echo '# scutil -d -v -r 0.0.0.0' >> reachability-info.txt
583 echo "#" >> reachability-info.txt
584 /usr/sbin/scutil -d -v -r 0.0.0.0 >> reachability-info.txt 2>&1
585
586 echo "#" >> reachability-info.txt
587 echo '# scutil -d -v -r 169.254.0.0' >> reachability-info.txt
588 echo "#" >> reachability-info.txt
589 /usr/sbin/scutil -d -v -r 169.254.0.0 >> reachability-info.txt 2>&1
590
591 echo "#" > nc-info.txt
592 echo '# scutil --nc list' >> nc-info.txt
593 echo "#" >> nc-info.txt
594 /usr/sbin/scutil --nc list >> nc-info.txt 2>&1
595
596 /usr/sbin/scutil -p --snapshot SCDynamicStore.plist 2>&1
597
598 }
599
600 #
601 # route
602 #
603 run_route () {
604
605 if [ ! -x /sbin/route ]; then
606 return
607 fi
608
609 echo "`date +"%Y-%m-%d %H:%M:%S"`: run_route" >> get-network-info.txt
610 echo "#" > route-info.txt
611 echo '# route -n -v get www.apple.com' >> route-info.txt
612 echo "#" >> route-info.txt
613 /sbin/route -n -v get www.apple.com >> route-info.txt 2>&1
614
615 echo "#" >> route-info.txt
616 echo '# route -n -v get 0.0.0.0' >> route-info.txt
617 echo "#" >> route-info.txt
618 /sbin/route -n -v get 0.0.0.0 >> route-info.txt 2>&1
619
620 }
621
622 #
623 # dig
624 #
625 run_dig () {
626
627 if [ ! -x /usr/bin/dig -o ! -f /etc/resolv.conf ]; then
628 return
629 fi
630
631 echo "`date +"%Y-%m-%d %H:%M:%S"`: run_dig" >> get-network-info.txt
632 echo "#" > dig-info.txt
633 echo '# dig -t any -c any www.apple.com' >> dig-info.txt
634 echo "#" >> dig-info.txt
635 /usr/bin/dig +time=2 -t any -c any www.apple.com >> dig-info.txt 2>/dev/null
636
637 }
638
639 #
640 # hostname
641 #
642 run_hostname () {
643
644 if [ ! -x /bin/hostname ]; then
645 return
646 fi
647
648 echo "`date +"%Y-%m-%d %H:%M:%S"`: run_hostname" >> get-network-info.txt
649 /bin/hostname > hostname.txt 2>&1
650
651 }
652
653 #
654 # lsof
655 #
656 run_lsof () {
657
658 if [ ! -x /usr/sbin/lsof ]; then
659 return
660 fi
661
662 echo "`date +"%Y-%m-%d %H:%M:%S"`: run_lsof" >> get-network-info.txt
663 ${PRIV} /usr/sbin/lsof +c 0 -X -n -O -P -T q > lsof.txt 2>&1 &
664 LSOF_PID=$!
665 # start a watchdog for lsof
666 (
667 WAIT_TIME=5
668 while [ $WAIT_TIME -gt 0 ]
669 do
670 ${PRIV} kill -0 ${LSOF_PID} 2>/dev/null
671 if [ $? -eq 0 ]; then
672 # lsof is [still] gathering data...
673 sleep 1
674 WAIT_TIME=$((WAIT_TIME - 1))
675 continue
676 fi
677
678 # lsof completed gathering data
679 break
680 done
681
682 if [ $WAIT_TIME -eq 0 ]; then
683 # lsof timed out
684 ${PRIV} kill ${LSOF_PID} 2>/dev/null
685 fi
686 ) &
687
688 }
689
690 #
691 # sysctl
692 #
693 run_sysctl () {
694
695 if [ ! -x /usr/sbin/sysctl ]; then
696 return
697 fi
698
699 echo "`date +"%Y-%m-%d %H:%M:%S"`: run_sysctl" >> get-network-info.txt
700 ${PRIV} /usr/sbin/sysctl -a > sysctl.txt 2>&1 &
701
702 }
703
704 start_pcap() {
705 #
706 # collect a packet capture if netdiagnose is available
707 #
708 if [ -x /usr/local/bin/netdiagnose ]; then
709 echo "`date +"%Y-%m-%d %H:%M:%S"`: start_pcap" >> get-network-info.txt
710 trap stop_pcap SIGINT
711 /usr/local/bin/netdiagnose -p "${REQUESTED_OUTDIR}" start sysdiagpcap 2>&1 1>/dev/null
712 PCAP_STARTED=1
713 fi
714 }
715
716 stop_pcap () {
717 if [ ${PCAP_STARTED} -ne 0 ]; then
718 trap '' SIGINT
719 /usr/local/bin/netdiagnose stop sysdiagpcap 2>&1 1>/dev/null
720 echo "`date +"%Y-%m-%d %H:%M:%S"`: stop_pcap" >> get-network-info.txt
721 fi
722 }
723
724 collect_ndf_info () {
725 run_lsof
726 run_sysctl
727 }
728
729 collect_sensitive_info () {
730
731 if [ "${COLLECT_PCAP}" == "Y" ]; then
732 start_pcap
733 fi
734
735 collect_state_dump_sensitive
736 run_ndp
737 run_arp
738 run_neutil
739 run_nettop
740 run_network_test
741 }
742
743 collect_info () {
744
745 if [ "${COLLECT_NDF_INFO}" == "Y" ]; then
746 collect_ndf_info
747 fi
748
749 if [ "${COLLECT_SENSITIVE_INFO}" == "Y" ]; then
750 collect_sensitive_info
751 fi
752
753 run_scutil
754 run_dig
755 run_ifconfig
756 run_netstat
757 run_ipconfig
758 run_setkey
759 run_skywalk
760 collect_vpn_logs
761 run_route
762 run_hostname
763
764 if [ "${COLLECT_CONFIGURATION_FILES}" == "Y" ]; then
765 collect_configuration_files
766 fi
767
768 stop_pcap
769 }
770
771 # __COMMAND_ROUTINES_END__
772
773 # __HELPER_ROUTINES_BEGIN__
774
775 usage () {
776
777 echo "Usage: get-network-info [-c] [-n] [-s] <info-directory>"
778 echo " -c collects system configuration files"
779 echo " -n collects NDF information (lsof)"
780 echo " -P do not collect a packet capture"
781 echo " -s collects sensitive information (ARP/NDP/mDNS cache)"
782 echo " <info-directory> path to directory where all the information will be collected"
783
784 }
785
786 is_outdir_valid () {
787
788 if [ "${REQUESTED_OUTDIR}" = "" ]; then
789 usage
790 exit 1
791 fi
792
793 if [ ! -d ${REQUESTED_OUTDIR} ]; then
794 echo "${REQUESTED_OUTDIR} does not exist"
795 exit 1
796 fi
797
798 if [ ! -w ${REQUESTED_OUTDIR} ]; then
799 echo "${REQUESTED_OUTDIR} is write-protected"
800 exit 1
801 fi
802 }
803
804 #
805 # Collect most used command output to be used later
806 #
807 optimize () {
808
809 if [ ! -x /sbin/ifconfig ]; then
810 return
811 fi
812
813 IF_LIST=`/sbin/ifconfig -l`
814
815 }
816
817 init_globals () {
818 REQUESTED_OUTDIR=""
819 COLLECT_SENSITIVE_INFO=""
820 COLLECT_CONFIGURATION_FILES=""
821 COLLECT_PCAP="Y"
822 PCAP_STARTED=0
823
824 }
825
826 # __HELPER_ROUTINES_END__
827
828 #
829 # __MAIN__
830 #
831 ARGS=`getopt cnPs $*`
832 if [ $? != 0 ]; then
833 usage
834 exit 1
835 fi
836
837 init_globals
838 process_opts
839 is_outdir_valid
840 setup
841 optimize
842 collect_info
843 wait
844
845 exit 0