1#!/bin/sh
2# Copyright (c) 2004-2014 Apple Inc.
3#
4# get-mobility-info
5#
6# Collect system & network configuration information.
7#
8
9PATH=/bin:/usr/bin:/sbin:/usr/sbin
10
11#
12# Disclaimer
13#
14cat <<_END_OF_DISCLAIMER
15
16This diagnostic tool generates files that allow Apple to investigate issues
17with your computer and help Apple to improve its products. The generated files
18may contain some of your personal information, which may include, but not be
19limited to, the serial number or similar unique number for your device, your
20user name, or your computer name. The information is used by Apple in
21accordance with its privacy policy (www.apple.com/privacy) and is not shared
22with any third party. By enabling this diagnostic tool and sending a copy of
23the generated files to Apple, you are consenting to Apple's use of the content
24of such files.
25
26_END_OF_DISCLAIMER
27
28/bin/echo "Press 'Enter' to continue."
29read reply
30
31#
32# Setup
33#
34PRIV=""
35if [ ${EUID} -ne 0 ]; then
36	PRIV="sudo"
37fi
38
39if [ -x /usr/bin/tail ]; then
40	TAIL_2000="/usr/bin/tail -n 2000"
41	TAIL_25000="/usr/bin/tail -n 25000"
42else
43	TAIL_2000="/bin/cat"
44	TAIL_25000="/bin/cat"
45fi
46
47OUT="mobility-info-`date +'%m.%d.%Y.%H%M%S'`"
48OUTDIR="/var/tmp"
49if [ -d ~/Desktop ]; then
50	OUTDIR=~/Desktop
51elif [ "`readlink /tmp`" = "private/var/tmp" ]; then
52	OUTDIR=/Library/Logs/CrashReporter
53	mkdir -p ${OUTDIR}
54fi
55
56umask 077
57
58WORKDIR=`mktemp -d -q "/tmp/${OUT}"`
59if [ $? -ne 0 ]; then
60	echo "Could not create snapshot directory"
61	exit 1
62fi
63
64GZ_EXT=""
65GZ_OPT=""
66if [ -x /usr/bin/gzip ]; then
67	GZ_EXT=".gz"
68	GZ_OPT="-z"
69fi
70
71ARCHIVE=`mktemp -q "${OUTDIR}/${OUT}.tar${GZ_EXT}"`
72if [ $? -ne 0 ]; then
73	echo "Could not create snapshot archive"
74	rm -rf "${WORKDIR}"
75	exit 1
76fi
77
78cd "${WORKDIR}"
79
80echo ""
81echo "Please wait, collecting information and statistics"
82echo ""
83
84#
85# Execute network reachability/DNS commands early
86#
87echo "#"						>  reachability-info
88echo '# scutil -d -v -r www.apple.com "" no-server'	>> reachability-info
89echo "#"						>> reachability-info
90scutil -d -v -r www.apple.com "" no-server		>> reachability-info	2>&1
91
92echo "#"						>> reachability-info
93echo '# scutil -d -v -r 0.0.0.0 no-server'		>> reachability-info
94echo "#"						>> reachability-info
95scutil -d -v -r 0.0.0.0          no-server		>> reachability-info	2>&1
96
97if [ -x /usr/bin/dig -a -f /etc/resolv.conf ]; then
98	/usr/bin/dig -t any -c any www.apple.com	> dig-results		2>/dev/null
99fi
100
101#
102# Signal "networkd" to log its "state" info. This logging will continue while
103# we execute a few other commands and should be complete by the time we collect
104# the log content.
105#
106if [ -x /usr/bin/killall ]; then
107	#
108	# request networkd state
109	#
110	${PRIV} /usr/bin/killall -INFO networkd					2>/dev/null
111
112	#
113	# discoveryd info
114	#
115	if [ -x /usr/libexec/discoveryd -a -x /usr/sbin/discoveryutil ]; then
116		${PRIV} pgrep -q -x discoveryd
117		if [ $? -eq 0 ]; then
118			P_ARG=""
119			case "`${PRIV} discoveryutil help 2>&1`" in
120			    Warning:* )
121				P_ARG="--priv"
122				;;
123			esac
124			#
125			# upgrade logging (if needed)
126			#
127			CLASS_o=`${PRIV} discoveryutil ${P_ARG} logclass`
128			CLASS_n=`${PRIV} discoveryutil ${P_ARG} logclass Cache`
129
130			LEVEL_o=`${PRIV} discoveryutil ${P_ARG} loglevel | awk '{ print $5 }'`
131			if [ ${LEVEL_o} -le 1 ]; then
132				LEVEL_n=`${PRIV} discoveryutil ${P_ARG} loglevel Intermediate | awk '{ print $5 }'`
133			else
134				LEVEL_n=${LEVEL_o}
135			fi
136
137			cp /dev/null						discoveryd-info
138			for c in			\
139				clientlisteners		\
140				configinterfaces	\
141				configresolvers		\
142				dnsproxystate		\
143				mdnsbrowses		\
144				mdnscachecontents	\
145				mdnscachestats		\
146				mdnslisteners		\
147				mdnsregistrations	\
148				nattraversals		\
149				udnscachecontents	\
150				udnscachestats		\
151				udnsresolvers		\
152				udnsunanswered		\
153
154			do
155				echo "#"					>> discoveryd-info
156				echo "# discoveryutil ${c}"			>> discoveryd-info
157				echo "#"					>> discoveryd-info
158				${PRIV} discoveryutil ${P_ARG} --timeout ${c}	>> discoveryd-info
159			done
160
161			if [ "$CLASS_o" != "$CLASS_n" ]; then
162				#
163				# restore log settings
164				#
165				${PRIV} discoveryutil ${P_ARG} lognoclass Cache		>/dev/null
166			fi
167
168			if [ "$LEVEL_o" != "$LEVEL_n" ]; then
169				${PRIV} discoveryutil ${P_ARG} loglevel ${LEVEL_o}	>/dev/null
170			fi
171
172			${PRIV} cat /var/run/com.apple.discoveryd-trace.sb	> com.apple.discoveryd-trace.sb	2>/dev/null
173		fi
174	fi
175
176	sleep 1
177fi
178
179#
180# processes
181#
182if [ -x /bin/ps ]; then
183	/bin/ps axlww					> ps			2>&1
184fi
185
186#
187# network interface configuration
188#
189if [ -x /sbin/ifconfig ]; then
190	/sbin/ifconfig -a -L -b -m -r -v -v		> ifconfig		2>&1
191	if [ $? -ne 0 ]; then
192		/sbin/ifconfig -a			> ifconfig		2>&1
193	fi
194fi
195
196#
197# network route configuration
198#
199if [ -x /usr/sbin/netstat ]; then
200	/usr/sbin/netstat -n -r -a -l			> netstat		2>&1
201fi
202
203#
204# DHCP configuration
205#
206if [ -x /sbin/ifconfig ]; then
207	for if in `/sbin/ifconfig -l`
208	do
209		case ${if} in
210		lo* )	;;
211		en* )	ipconfig getpacket ${if}	> ipconfig-${if}	2>&1
212			;;
213		esac
214	done
215fi
216
217#
218# AirPort info
219#
220if [ -x /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport ]; then
221	/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport --getinfo	\
222							> airport		2>&1
223fi
224
225#
226# collect wifi dump
227#
228if [ -x /usr/bin/wdutil -a -x /bin/ls ]; then
229	${PRIV} /usr/bin/wdutil dump
230	mkdir -p "wifi_dump"
231	/bin/ls -1 /private/tmp/wifi-*						2>/dev/null	\
232	| while read log
233	do
234		if [ -f "${log}" ]; then
235			b="`basename ${log}`"
236			${PRIV} cat "${log}"		> "wifi_dump/${b}"	2>&1
237		fi
238	done
239fi
240
241#
242# OS info
243#
244if [ -e /System/Library/CoreServices/SystemVersion.plist ]; then
245	cat /System/Library/CoreServices/SystemVersion.plist	\
246							> SystemVersion.plist	2>&1
247fi
248
249#
250# IOKit info
251#
252if [ -x /usr/sbin/ioreg ]; then
253	/usr/sbin/ioreg -i -l -w 0			>  ioreg		2>&1
254	/usr/sbin/ioreg -i -l -p IODeviceTree -w 0	>> ioreg		2>&1
255fi
256
257#
258# Power Management info
259#
260if [ -x /usr/bin/pmset ]; then
261	echo "#"							>  pmset
262	echo "# pmset -g everything"					>> pmset
263	echo "#"							>> pmset
264	/usr/bin/pmset -g everything 2>/dev/null  | ${TAIL_25000}	>> pmset
265fi
266
267#
268# Host name
269#
270if [ -x /bin/hostname ]; then
271	/bin/hostname					> hostname		2>&1
272fi
273
274#
275# Host configuration
276#
277if [ -x /usr/bin/hostinfo ]; then
278	/usr/bin/hostinfo				> hostinfo		2>&1
279fi
280if [ -e /etc/hostconfig ]; then
281	cat /etc/hostconfig				> etc.hostconfig	2>&1
282fi
283
284#
285# DNS configuration
286#
287scutil --dns						> dns-configuration	2>&1
288if [ -e /etc/resolv.conf ]; then
289	cat /etc/resolv.conf				> etc.resolv.conf	2>&1
290fi
291if [ -e /var/run/resolv.conf ]; then
292	cat /var/run/resolv.conf			> var.run.resolv.conf	2>&1
293fi
294if [ -e /etc/resolver ]; then
295	tar -c -H /etc/resolver				> etc.resolver.tar	2>/dev/null
296fi
297
298#
299# Proxy configuration
300#
301scutil -d -v --proxy					> proxy-configuration	2>&1
302
303#
304# Network information
305#
306if [ -x /sbin/ifconfig ]; then
307	echo "#"					>  network-information
308	echo "# scutil --nwi"				>> network-information
309	echo "#"					>> network-information
310	scutil --nwi					>> network-information	2>&1
311	for if in `/sbin/ifconfig -l`
312	do
313		echo ""					>> network-information
314		echo "#"				>> network-information
315		echo "# scutil --nwi ${if}"		>> network-information
316		echo "#"				>> network-information
317		scutil --nwi ${if}			>> network-information	2>&1
318	done
319fi
320
321#
322# System / network preferences
323#
324for f in										\
325	/Library/Preferences/SystemConfiguration/NetworkInterfaces.plist		\
326	/Library/Preferences/SystemConfiguration/com.apple.PowerManagement.plist	\
327	/Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist	\
328	/Library/Preferences/SystemConfiguration/com.apple.nat.plist			\
329	/Library/Preferences/SystemConfiguration/com.apple.smb.server.plist		\
330	/Library/Preferences/SystemConfiguration/com.apple.wifi.plist			\
331	/Library/Preferences/SystemConfiguration/preferences.plist			\
332	/Library/Preferences/com.apple.alf.plist					\
333	/Library/Preferences/com.apple.sharing.firewall.plist				\
334	/Library/Preferences/com.apple.networkextension.plist				\
335	/Library/Preferences/com.apple.networkextension.control.plist			\
336	/Library/Preferences/com.apple.networkextension.necp.plist			\
337	/Library/Preferences/com.apple.wwand.plist					\
338
339do
340	if [ -e "${f}" ]; then
341		b="`basename ${f}`"
342		cat "${f}"				> "${b}"		2>&1
343	fi
344done
345
346#
347# System / network preferences (from other volumes)
348#
349/bin/ls /Volumes 2>/dev/null								\
350| while read volume
351do
352	V_PATH="/Volumes/${volume}"
353	if [ -h "${V_PATH}" ]; then
354		# if the path is a symlink
355		continue
356	fi
357	for f in									\
358		/Library/Preferences/SystemConfiguration/Networkinterfaces.plist	\
359		/Library/Preferences/SystemConfiguration/preferences.plist		\
360
361	do
362		if [ -f "${V_PATH}/${f}" ]; then
363			mkdir -p "OtherPreferences/${volume}"
364			b="`basename ${f}`"
365			cat "${V_PATH}/${f}"		> "OtherPreferences/${volume}/${b}"	2>&1
366		fi
367	done
368done
369
370#
371# InternetSharing
372#
373if   [ -e /etc/bootpd.plist ]; then
374	cat /etc/bootpd.plist							> bootpd.plist			2>&1
375	cat /etc/com.apple.named.proxy.conf					> com.apple.named.proxy.conf	2>/dev/null
376elif [ -e /Library/Preferences/SystemConfiguration/bootpd.plist ]; then
377	cat /Library/Preferences/SystemConfiguration/bootpd.plist		> bootpd.plist			2>&1
378	cat /Library/Preferences/SystemConfiguration/com.apple.named.proxy.conf	> com.apple.named.proxy.conf	2>/dev/null
379fi
380
381#
382# configd's cache
383#
384${PRIV} scutil -p --snapshot
385if [ -f /var/tmp/configd-store.plist ]; then
386	cat /var/tmp/configd-store.plist		> configd-store.plist	2>&1
387fi
388if [ -f /var/tmp/configd-pattern.plist ]; then
389	cat /var/tmp/configd-pattern.plist		> configd-pattern.plist	2>&1
390fi
391if [ -f /var/tmp/configd-session.plist ]; then
392	cat /var/tmp/configd-session.plist		> configd-session.plist	2>&1
393fi
394if [ -f /var/tmp/configd-state ]; then
395	cat /var/tmp/configd-state			> configd-state		2>&1
396fi
397if [ -f /var/tmp/configd-reachability ]; then
398	cat /var/tmp/configd-reachability		> configd-reachability	2>&1
399fi
400
401#
402# mounted filesystems
403#
404mount							> mounted-filesystems	2>&1
405
406${PRIV} cat /etc/hosts 					> etc.hosts		2>/dev/null
407
408#
409# kernel extensions statistic
410#
411if   [ -x /usr/sbin/kextstat ]; then
412	/usr/sbin/kextstat				> kextstat		2>&1
413fi
414
415#
416# network statistics
417#
418/bin/echo -n ""							>  network-statistics
419
420if   [ -x /usr/sbin/arp ]; then
421	echo "#"						>> network-statistics
422	echo "# arp -n -a"					>> network-statistics
423	echo "#"						>> network-statistics
424	/usr/sbin/arp -n -a					>> network-statistics	2>&1
425fi
426
427if [ -x /usr/sbin/netstat ]; then
428	echo "#"						>> network-statistics
429	echo "# netstat -A -a -l -n"				>> network-statistics
430	echo "#"						>> network-statistics
431	/usr/sbin/netstat -A -a -l -n				>> network-statistics	2>&1
432
433	echo "#"						>> network-statistics
434	echo "# netstat -s"					>> network-statistics
435	echo "#"						>> network-statistics
436	/usr/sbin/netstat -s					>> network-statistics	2>&1
437
438	echo "#"						>> network-statistics
439	echo "# netstat -mmm"					>> network-statistics
440	echo "#"						>> network-statistics
441	/usr/sbin/netstat -mmm					>> network-statistics	2>&1
442
443	echo "#"						>> network-statistics
444	echo "# netstat -i -n -d"				>> network-statistics
445	echo "#"						>> network-statistics
446	/usr/sbin/netstat -i -n -d				>> network-statistics	2>&1
447
448	echo "#"						>> network-statistics
449	echo "# netstat -g -n -s"				>> network-statistics
450	echo "#"						>> network-statistics
451	/usr/sbin/netstat -g -n -s				>> network-statistics	2>&1
452
453	echo "#"						>> network-statistics
454	echo "# netstat -i -x R"				>> network-statistics
455	echo "#"						>> network-statistics
456	/usr/sbin/netstat -i -x R				>> network-statistics	2>&1
457	echo "#"						>> network-statistics
458
459	echo "# netstat -a -n -p mptcp"				>> network-statistics
460	echo "#"						>> network-statistics
461	/usr/sbin/netstat -a -n -p mptcp			>> network-statistics	2>/dev/null
462
463	echo "#"						>> network-statistics
464	echo "# netstat -s -p mptcp"				>> network-statistics
465	echo "#"						>> network-statistics
466	/usr/sbin/netstat -s -p mptcp				>> network-statistics	2>/dev/null
467
468	if [ -x /sbin/ifconfig ]; then
469		for if in `/sbin/ifconfig -l`
470		do
471			`/sbin/ifconfig -v ${if} | grep -q TXSTART`
472			if [ $? -eq 0 ]; then
473				echo "#"			>> network-statistics
474				echo "# netstat -qq -I ${if}"	>> network-statistics
475				echo "#"			>> network-statistics
476				/usr/sbin/netstat -qq -I ${if}	>> network-statistics	2>&1
477			fi
478			`/sbin/ifconfig -v ${if} | grep -q RXPOLL`
479			if [ $? -eq 0 ]; then
480				echo "#"			>> network-statistics
481				echo "# netstat -Q -I ${if}"	>> network-statistics
482				echo "#" 			>> network-statistics
483				/usr/sbin/netstat -Q -I ${if}	>> network-statistics   2>&1
484			fi
485		done
486	fi
487fi
488
489if [ -x /usr/sbin/ndp ]; then
490	echo "#"					>> network-statistics
491	echo "# ndp -n -a"				>> network-statistics
492	echo "#"					>> network-statistics
493	/usr/sbin/ndp -n -a				>> network-statistics	2>&1
494
495	echo "#"					>> network-statistics
496	echo "# ndp -n -p"				>> network-statistics
497	echo "#"					>> network-statistics
498	/usr/sbin/ndp -n -p				>> network-statistics	2>&1
499
500	echo "#"					>> network-statistics
501	echo "# ndp -n -r"				>> network-statistics
502	echo "#"					>> network-statistics
503	/usr/sbin/ndp -n -r				>> network-statistics	2>&1
504
505	if [ -x /sbin/ifconfig ]; then
506		for if in `/sbin/ifconfig -l`
507		do
508			echo "#"			>> network-statistics
509			echo "# ndp -i ${if}"		>> network-statistics
510			echo "#"			>> network-statistics
511			/usr/sbin/ndp -i ${if}		>> network-statistics	2>&1
512		done
513	fi
514fi
515
516if [ -x /sbin/pfctl ]; then
517	echo "#"					>  pf
518	echo "# pfctl -s all"				>> pf
519	echo "#"					>> pf
520	${PRIV} /sbin/pfctl -s all			>> pf			2>&1
521	echo "=============================="		>> pf
522	echo "#"					>> pf
523	echo "# pfctl -s References"			>> pf
524	echo "#"					>> pf
525	${PRIV} /sbin/pfctl -s References		>> pf			2>&1
526	for ANCHOR in `${PRIV} pfctl -s Anchors -v 2>/dev/null`
527	do
528		echo "=============================="	>> pf
529		echo "#"				>> pf
530		echo "# pfctl -a ${ANCHOR} -s all"	>> pf
531		echo "#"				>> pf
532		${PRIV} /sbin/pfctl -a ${ANCHOR} -s all	>> pf			2>&1
533	done
534fi
535
536#
537# mach port info
538#
539if [ -x /usr/local/bin/lsmp ]; then
540	${PRIV} /usr/local/bin/lsmp -a -v		> lsmp			2>&1
541fi
542
543#
544# open files
545#
546if [ -x /usr/sbin/lsof ]; then
547	${PRIV} /usr/sbin/lsof -n -P -T q		> lsof			2>&1
548fi
549
550#
551# [lib]dispatch info
552#
553if [ -x /usr/local/bin/ddt ]; then
554    /bin/echo -n ""					>  dispatch-info
555    for BIN in		\
556	configd		\
557	discoveryd	\
558
559    do
560	echo "#"					>> dispatch-info
561	echo "# ddt -vkp ${BIN}"			>> dispatch-info
562	echo "#"					>> dispatch-info
563	${PRIV} /usr/local/bin/ddt -vkp ${BIN}		>> dispatch-info	2>&1
564    done
565fi
566
567#
568# OpenDirectory info
569#
570if [ -x /usr/bin/odutil ]; then
571	echo "#"					>  od-info
572	echo "# odutil show all"			>> od-info
573	echo "#"					>> od-info
574	${PRIV} /usr/bin/odutil show all		>> od-info		2>&1
575fi
576
577#
578# IPsec configuration
579#
580if [ -x /usr/sbin/setkey -a -x /usr/bin/perl ]; then
581	echo "#"						>  ipsec
582	echo "# setkey -D"					>> ipsec
583	echo "#"						>> ipsec
584	${PRIV} /usr/sbin/setkey -D				\
585	| /usr/bin/perl -M'Digest::MD5 qw(md5_hex)' -l -n -e '
586		if (/^(\s+[AE]:\s+\S+\s+)"?(.*)"?\s*$/) {
587			printf "%s[MD5:%s]%s\n", $1, md5_hex($2 . "\n"), $3;
588		} else {
589			printf "%s\n", $_;
590		}
591	'							>> ipsec
592
593	echo ""							>> ipsec
594	echo "#"						>> ipsec
595	echo "# setkey -Pp -D"					>> ipsec
596	echo "#"						>> ipsec
597	${PRIV} /usr/sbin/setkey -Pp -D				>> ipsec
598
599	for CF in /var/run/racoon/*.conf
600	do
601		if [ ! -r "${CF}" ]; then
602			continue
603		fi
604
605		echo ""						>> ipsec
606		echo "#"					>> ipsec
607		echo "# ${CF}"					>> ipsec
608		echo "#"					>> ipsec
609		${PRIV} cat ${CF}				\
610		| /usr/bin/perl -M'Digest::MD5 qw(md5_hex)' -l -n -e '
611			if (/^(\s+shared_secret\s+use\s+)"?([^\s;"]+)"?(.*)/) {
612				printf "%s[MD5:%s]%s\n", $1, md5_hex($2 . "\n"), $3;
613			} else {
614				printf "%s\n", $_;
615			}
616		'						>> ipsec
617	done
618fi
619
620#
621# Kerberos configuration
622#
623if [ -x /usr/bin/klist ]; then
624	echo "#"					>  kerberos
625	echo "# klist --verbose --all-content"		>> kerberos
626	echo "#"					>> kerberos
627	klist --verbose --all-content			>> kerberos	2>&1
628
629	echo "#"					>> kerberos
630	echo "# ktutil list"				>> kerberos
631	echo "#"					>> kerberos
632	${PRIV} /usr/sbin/ktutil --verbose list		>> kerberos	2>&1
633
634	echo "#"					>> kerberos
635	echo "# gsstool list --verbose"			>> kerberos
636	echo "#"					>> kerberos
637	/System/Library/PrivateFrameworks/Heimdal.framework/Helpers/gsstool list --verbose >> kerberos	2>&1
638fi
639
640#
641# system profiler
642#
643if [ -x /usr/sbin/system_profiler ]; then
644	system_profiler -xml 	SPEthernetDataType 	\
645				SPFibreChannelDataType	\
646				SPFireWireDataType 	\
647				SPFirewallDataType 	\
648				SPModemDataType		\
649				SPNetworkDataType 	\
650				SPThunderboltDataType 	\
651				SPWWANDataType 		\
652				SPAirPortDataType 	> system_profiler.spx	2>/dev/null
653fi
654
655#
656# system usage statistics
657#
658/bin/echo -n ""						> system-statistics
659
660if [ -x /usr/bin/uptime ]; then
661	echo "#"					>> system-statistics
662	echo "# uptime"					>> system-statistics
663	echo "#"					>> system-statistics
664	/usr/bin/uptime					>> system-statistics	2>&1
665fi
666
667if [ -x /usr/sbin/sysctl ]; then
668	echo "#"					>> system-statistics
669	echo "# sysctl kern hw net debug"		>> system-statistics
670	echo "#"					>> system-statistics
671	/usr/sbin/sysctl kern hw net debug		>> system-statistics	2>&1
672fi
673
674if [ -x /usr/bin/zprint ]; then
675	echo "#"					>> system-statistics
676	echo "# zprint"					>> system-statistics
677	echo "#"					>> system-statistics
678	${PRIV} /usr/bin/zprint				>> system-statistics	2>&1
679fi
680
681if [ -x /usr/sbin/lsof -a -x /bin/ls ]; then
682	N=0
683	/bin/ls -1	/Library/Preferences/SystemConfiguration/*-lock		\
684			2>/dev/null						\
685	| while read lock
686	do
687		if [ ${N} -eq 0 ]; then
688			echo "#"					>> system-statistics
689			echo "# lsof [SCPreferences lock files]"	>> system-statistics
690		fi
691		N=`expr ${N} + 1`
692
693		echo "#"						>> system-statistics
694		${PRIV} /usr/sbin/lsof -- ${lock}			>> system-statistics	2>&1
695	done
696fi
697
698#
699# collect executable and plugin info
700#
701report_binary_info()
702{
703    if [ ! -f "${1}" ]; then
704	return
705    fi
706
707    VERSION=`what "${1}"`
708    echo "${VERSION}"					>> versions	2>&1
709
710    SUM=`sum "${1}"`
711    echo "\tsum: ${SUM}"				>> versions	2>&1
712
713    LSINFO=`ls -lu "${1}"`
714    echo "\tadditional info: ${LSINFO}"			>> versions	2>&1
715
716    echo ""						>> versions	2>&1
717}
718
719get_binary_info()
720{
721    for BIN in										\
722	/usr/libexec/bootpd								\
723	/usr/libexec/configd								\
724	/usr/libexec/discoveryd								\
725	/usr/sbin/awacsd								\
726	/usr/sbin/pppd									\
727	/usr/sbin/racoon								\
728	/usr/libexec/misd								\
729	/usr/libexec/InternetSharing							\
730	/System/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration	\
731
732    do
733	report_binary_info "${BIN}"
734    done
735
736    if [ -x /usr/bin/xcode-select -a -x /usr/bin/xcodebuild -a -x /usr/bin/xcrun ]; then
737	SDKPATH="`xcode-select --print-path 2>/dev/null`"
738	if [ $? -eq 0 -a -n "${SDKPATH}" ]; then
739	    /usr/bin/xcodebuild -showsdks 2>/dev/null	\
740	    | grep iphone				\
741	    | awk '{ print $NF }'			\
742	    | while read SDK
743	    do
744		SDKPATH="`xcrun --sdk $SDK --show-sdk-path`"
745		for BIN in										\
746		    /usr/libexec/configd_sim								\
747		    /System/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration	\
748
749		do
750		    report_binary_info "${SDKPATH}${BIN}"
751		done
752	    done
753	else
754	    echo "*** NO SDKs ***"	>> versions
755	    echo ""			>> versions
756	fi
757    fi
758}
759
760get_plugins_info()
761{
762    num=0
763    cd /System/Library/SystemConfiguration
764    for PLUGIN in *.bundle
765    do
766	plugins[$num]="${PLUGIN}"
767	num=$(( $num + 1 ))
768    done
769
770    cd "${WORKDIR}"
771
772    for PLUGIN in "${plugins[@]}"
773    do
774	PLUGIN_DIR="/System/Library/SystemConfiguration/${PLUGIN}"
775	PLUGIN_INF="${PLUGIN_DIR}/Contents/Info.plist"
776	if [ ! -f "${PLUGIN_INF}" ]; then
777	    PLUGIN_INF="${PLUGIN_DIR}/Info.plist"
778	    if [ ! -f "${PLUGIN_INF}" ]; then
779		echo "${PLUGIN_INF}: No Info.plist"		>> versions		2>&1
780	    fi
781	fi
782
783	echo "${PLUGIN}"					>> versions		2>&1
784
785	ENABLED="Enabled"
786	BOOL=`scutil --get "${PLUGIN_INF}" / Enabled					2>/dev/null`
787	if [ $? -eq 0 ]; then
788	    if [ ${BOOL} = "TRUE" ]; then
789		ENABLED="Enabled*"
790	    else
791		ENABLED="Disabled"
792	    fi
793	fi
794	echo "\t${ENABLED}"					>> versions		2>&1
795
796	VERBOSE=""
797	BOOL=`scutil --get "${PLUGIN_INF}" / Verbose					2>/dev/null`
798	if [ $? -eq 0 ]; then
799	    if [ ${BOOL} = "TRUE" ]; then
800		VERBOSE="Verbose"
801	    fi
802	fi
803	if [ -n "${VERBOSE}" ]; then
804		echo "\t${VERBOSE}"				>> versions		2>&1
805	fi
806
807	VERSION=`scutil --get "${PLUGIN_INF}" / CFBundleVersion				2>/dev/null`
808	if [ $? -eq 1 ]; then
809		VERSION=`scutil --get "${PLUGIN_INF}" / CFBundleShortVersionString	2>/dev/null`
810	fi
811	echo "\tVersion: ${VERSION}"				>> versions		2>&1
812
813	if [ -f "${PLUGIN_DIR}/Contents/MacOS/${PLUGIN%.*}" ]; then
814	    SUM=`sum "${PLUGIN_DIR}/Contents/MacOS/${PLUGIN%.*}"`
815	    echo "\tsum: ${SUM}"				>> versions		2>&1
816
817	    LSINFO=`ls -lu "${PLUGIN_DIR}/Contents/MacOS/${PLUGIN%.*}"`
818	    echo "\tadditional info: ${LSINFO}"			>> versions		2>&1
819	elif [ -f "${PLUGIN_DIR}/${PLUGIN%.*}" ]; then
820	    SUM=`sum "${PLUGIN_DIR}/${PLUGIN%.*}"`
821	    echo "\tsum: ${SUM}"				>> versions		2>&1
822
823	    LSINFO=`ls -lu "${PLUGIN_DIR}/${PLUGIN%.*}"`
824	    echo "\tadditional info: ${LSINFO}"			>> versions		2>&1
825	fi
826
827	echo ""							>> versions		2>&1
828    done
829}
830
831if [ -x /usr/bin/what -a -x /usr/bin/sum -a -x /bin/ls ]; then
832	get_binary_info
833	get_plugins_info
834fi
835
836#
837# to give a chance for "networkd" to finish dumping its state, the last
838# thing we do is collect the logs
839#
840
841#
842# system log, kernel.log, early boot log messages
843#
844if [ -x /usr/bin/syslog ]; then
845	#
846	# save the recent activity
847	#
848	${PRIV} /usr/bin/syslog -T local.3					\
849		| ${TAIL_25000}							> syslog
850
851	#
852	# save just the "kernel" activity (in case some of the
853	# interesting/relevant message are before the messages
854	# captured above.
855	#
856	${PRIV} /usr/bin/syslog -T local.3 -k Facility kern			\
857		| ${TAIL_25000}							> kernel
858
859	if [ -d /var/log/DiagnosticMessages ]; then
860		# save any MessageTracer activity
861		${PRIV} /usr/bin/syslog	-d /var/log/DiagnosticMessages		\
862					-F raw					\
863					-T local.3				\
864			| ${TAIL_25000}						> DiagnosticMessages
865	fi
866else
867	if [ -f /var/log/system.log ]; then
868		${PRIV} ${TAIL_25000} /var/log/system.log			> system.log
869	fi
870	if [ -f /var/log/kernel.log ]; then
871		${PRIV} ${TAIL_25000} /var/log/kernel.log			> kernel.log
872	fi
873fi
874if [ -x /sbin/dmesg ]; then
875	${PRIV} /sbin/dmesg							> dmesg
876fi
877
878#
879# IPConfiguration log
880#
881if [ -f /var/log/com.apple.IPConfiguration.bootp ]; then
882	${PRIV} ${TAIL_2000} /var/log/com.apple.IPConfiguration.bootp	\
883							> com.apple.IPConfiguration.bootp
884fi
885
886#
887# ppp log file(s)
888#
889scutil <<_END_OF_INPUT				\
890| awk -F' *: *'					\
891    '						\
892     /Logfile : / {				\
893       if (index($2, "/") == 1) { print $2 }	\
894       else { print "/var/log/ppp/" $2 }	\
895     }						\
896     END {					\
897       print "/tmp/pppotcp.log"			\
898     }						\
899    '						\
900| sort -u					\
901| while read logFile
902open
903show Setup:/Network/Service/[^/]+/PPP pattern
904quit
905_END_OF_INPUT
906do
907	if [ -f "${logFile}" ]; then
908		b="`basename ${logFile}`"
909		cat "${logFile}"			> "${b}"		2>&1
910	fi
911done
912
913#
914# application firewall log
915#
916if [ -f /var/log/appfirewall.log ]; then
917	${PRIV} ${TAIL_2000} /var/log/appfirewall.log	> appfirewall.log
918fi
919
920if [ -x /bin/ls ]; then
921	#
922	# collect crash reports
923	#
924	for daemon in				\
925			InternetSharing		\
926			SCHelper		\
927			SCMonitor		\
928			awacsd			\
929			bootpd			\
930			configd			\
931			discoveryd		\
932			discoveryd_helper	\
933			eapolclient		\
934			pppd			\
935			racoon			\
936			socketfilterfw		\
937
938	do
939		/bin/ls -1	/Library/Logs/DiagnosticReports/${daemon}_*.crash	\
940				/Library/Logs/DiagnosticReports/${daemon}_*.ips		\
941				/Library/Logs/CrashReporter/${daemon}_*.crash		\
942				/Library/Logs/CrashReporter/${daemon}_*.ips		\
943				/Library/Logs/CrashReporter/${daemon}_*.plist		\
944				2>/dev/null						\
945		| while read log
946		do
947			if [ -f "${log}" ]; then
948				b="`basename ${log}`"
949				${PRIV} cat "${log}"		> "${b}"		2>&1
950			fi
951		done
952	done
953
954	#
955	# collect any verbose logging output
956	#
957	/bin/ls -1	/Library/Logs/CrashReporter/com.apple.networking.*.log*		\
958			2>/dev/null							\
959	| while read log
960	do
961		if [ -f "${log}" ]; then
962			b="`basename ${log}`"
963			${PRIV} cat "${log}"			> "${b}"		2>&1
964		fi
965	done
966fi
967
968#
969# stackshot
970#
971if [ -x /usr/local/bin/crstackshot ]; then
972	/usr/local/bin/crstackshot				2>/dev/null
973fi
974
975#
976# collect everything into a single archive
977#
978cd "${WORKDIR}/.."
979tar -c ${GZ_OPT} -f "${ARCHIVE}" "${OUT}"
980rm -rf "${WORKDIR}"
981
982if [ ${UID} -eq 0 ]; then
983	if [ -n "${SUDO_UID}" -a -n "${SUDO_GID}" ]; then
984		if [ ${UID} -ne ${SUDO_UID} ]; then
985			chown ${SUDO_UID}:${SUDO_GID} "${ARCHIVE}"
986		fi
987	fi
988fi
989
990echo "Network data collected to \"${ARCHIVE}\""
991
992