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