2 # Copyright (c) 2004-2011 Apple Inc.
6 # Collect system & network configuration information.
9 PATH
=/bin
:/usr
/bin
:/sbin
:/usr
/sbin
12 if [ ${EUID} -ne 0 ]; then
16 OUT
="mobility-info-`date +'%m.%d.%Y.%H%M%S'`"
18 if [ -d ~
/Desktop
]; then
20 elif [ "`readlink /tmp`" = "private/var/tmp" ]; then
21 OUTDIR
=/Library
/Logs
/CrashReporter
/SystemConfiguration
27 WORKDIR
=`mktemp -d -q "/tmp/${OUT}"`
29 echo "Could not create snapshot directory"
35 if [ -x /usr
/bin
/gzip ]; then
40 ARCHIVE
=`mktemp -q "${OUTDIR}/${OUT}.tar${GZ_EXT}"`
42 echo "Could not create snapshot archive"
55 # network interface configuration
57 ifconfig
-a -L -b -m -r -v > ifconfig
2>&1
59 ifconfig
-a > ifconfig
2>&1
63 # network route configuration
65 netstat
-n -r -a -l > netstat
2>&1
70 for if in `ifconfig -l`
74 en
* ) ipconfig getpacket
${if} > ipconfig
-${if} 2>&1
82 if [ -x /System
/Library
/PrivateFrameworks
/Apple80211.framework
/Resources
/airport
]; then
83 /System
/Library
/PrivateFrameworks
/Apple80211.framework
/Resources
/airport
--getinfo \
90 if [ -e /System
/Library
/CoreServices
/SystemVersion.plist
]; then
91 cat /System
/Library
/CoreServices
/SystemVersion.plist \
92 > SystemVersion.plist
2>&1
94 if [ -e /System
/Library
/CoreServices
/ServerVersion.plist
]; then
95 cat /System
/Library
/CoreServices
/ServerVersion.plist \
96 > ServerVersion.plist
2>&1
102 ioreg
-i -l -w 0 > ioreg
2>&1
103 ioreg
-i -l -p IODeviceTree
-w 0 >> ioreg
2>&1
108 hostname
> hostname
2>&1
113 hostinfo
> hostinfo
2>&1
114 if [ -e /etc
/hostconfig
]; then
115 cat /etc
/hostconfig
> etc.hostconfig
2>&1
121 scutil
--dns > dns
-configuration 2>&1
122 if [ -e /etc
/resolv.conf
]; then
123 cat /etc
/resolv.conf
> etc.resolv.conf
2>&1
125 if [ -e /var
/run
/resolv.conf
]; then
126 cat /var
/run
/resolv.conf
> var.run.resolv.conf
2>&1
130 # Proxy configuration
132 scutil
--proxy > proxy
-configuration 2>&1
135 # System / network preferences
138 /Library
/Preferences
/SystemConfiguration
/NetworkInterfaces.plist \
139 /Library
/Preferences
/SystemConfiguration
/com.apple.PowerManagement.plist \
140 /Library
/Preferences
/SystemConfiguration
/com.apple.airport.preferences.plist \
141 /Library
/Preferences
/SystemConfiguration
/com.apple.nat.plist \
142 /Library
/Preferences
/SystemConfiguration
/com.apple.network.identification.plist \
143 /Library
/Preferences
/SystemConfiguration
/com.apple.smb.server.plist \
144 /Library
/Preferences
/SystemConfiguration
/com.apple.wifi.plist \
145 /Library
/Preferences
/SystemConfiguration
/preferences.plist \
146 /Library
/Preferences
/com.apple.alf.plist \
147 /Library
/Preferences
/com.apple.sharing.firewall.plist \
148 /Library
/Preferences
/com.apple.wwand.plist \
151 if [ -e "${f}" ]; then
153 cat "${f}" > "${b}" 2>&1
160 if [ -e /etc
/bootpd.plist
]; then
161 cat /etc
/bootpd.plist
> bootpd.plist
2>&1
162 cat /etc
/com.apple.named.proxy.conf
> com.apple.named.proxy.conf
2>&1
163 elif [ -e /Library
/Preferences
/SystemConfiguration
/bootpd.plist
]; then
164 cat /Library
/Preferences
/SystemConfiguration
/bootpd.plist
> bootpd.plist
2>&1
165 cat /Library
/Preferences
/SystemConfiguration
/com.apple.named.proxy.conf
> com.apple.named.proxy.conf
2>&1
171 ${PRIV} scutil
-p <<_END_OF_INPUT
176 if [ -f /var
/tmp
/configd
-store.plist
]; then
177 cat /var
/tmp
/configd
-store.plist
> configd
-store.plist
2>&1
179 if [ -f /var
/tmp
/configd
-pattern.plist
]; then
180 cat /var
/tmp
/configd
-pattern.plist
> configd
-pattern.plist
2>&1
182 if [ -f /var
/tmp
/configd
-session.plist
]; then
183 cat /var
/tmp
/configd
-session.plist
> configd
-session.plist
2>&1
185 if [ -f /var
/tmp
/configd
-state ]; then
186 cat /var
/tmp
/configd
-state > configd
-state 2>&1
190 # check configd's executable
192 if [ -x /usr
/bin
/codesign
]; then
193 echo "#" >> configd
-state
194 echo "# codesign --verbose --display --entitlements - /usr/libexec/configd" >> configd
-state
195 echo "#" >> configd
-state
196 /usr
/bin
/codesign
--verbose --display --entitlements - /usr
/libexec
/configd
>> configd
-state 2>&1
198 echo "#" >> configd
-state
199 echo "# codesign --verbose --verify /usr/libexec/configd" >> configd
-state
200 echo "#" >> configd
-state
201 /usr
/bin
/codesign
--verbose --verify /usr
/libexec
/configd
>> configd
-state 2>&1
205 # network reachability
207 scutil
-d -v -r www.apple.com
> reachability
-info 2>&1
208 if [ -x /usr
/bin
/dig -a -f /etc
/resolv.conf
]; then
209 /usr
/bin
/dig -t any
-c any www.apple.com
> dig-results 2>/dev
/null
213 # mounted filesystems
215 mount
> mounted
-filesystems 2>&1
220 if [ -x /usr
/bin
/killall
]; then
221 ${PRIV} killall
-INFO mDNSResponder
223 # and wait a short amount of time for mDNSResponder
224 # to actually log the requested information
231 if [ -x /usr
/sbin
/awacsd
-a -x /usr
/bin
/killall
]; then
232 ${PRIV} killall
-INFO awacsd
2>/dev
/null
234 # and wait a short amount of time for awacsd
235 # to actually log the requested information
240 # system log, kernel.log, early boot log messages
242 if [ -x /usr
/bin
/syslog
]; then
243 # save the recent activity
244 ${PRIV} syslog
| tail -n 25000 > syslog
246 # save just the "kernel" activity (in case some of the
247 # interesting/relevant message are before the messages
249 ${PRIV} syslog
-k Facility kern
| tail -n 25000 > kernel
251 if [ -d /var
/log
/DiagnosticMessages
]; then
252 # save any MessageTracer activity
253 ${PRIV} syslog
-d /var
/log
/DiagnosticMessages \
256 | tail -n 25000 > DiagnosticMessages
259 if [ -f /var
/log
/system.log
]; then
260 ${PRIV} tail -n 25000 /var
/log
/system.log
> system.log
262 if [ -f /var
/log
/kernel.log
]; then
263 ${PRIV} tail -n 25000 /var
/log
/kernel.log
> kernel.log
266 ${PRIV} dmesg
> dmesg
269 # IPConfiguration log
271 if [ -f /var
/log
/com.apple.IPConfiguration.bootp
]; then
272 ${PRIV} tail -n 2000 /var
/log
/com.apple.IPConfiguration.bootp \
273 > com.apple.IPConfiguration.bootp
279 scutil
<<_END_OF_INPUT \
283 if (index($2, "/") == 1) { print $2 } \
284 else { print "/var/log/ppp/" $2 } \
287 print "/tmp/pppotcp.log" \
293 show Setup:/Network/Service/[^/]+/PPP pattern
297 if [ -f "${logFile}" ]; then
298 b
="`basename ${logFile}`"
299 cat "${logFile}" > "${b}" 2>&1
304 # application firewall log
306 if [ -f /var
/log
/appfirewall.log
]; then
307 ${PRIV} tail -n 2000 /var
/log
/appfirewall.log
> appfirewall.log
311 # kernel extensions statistic
313 if [ -x /usr
/sbin
/kextstat
]; then
314 kextstat
> kextstat
2>&1
315 elif [ -x /usr
/sbin
/kmodstat
]; then
316 kmodstat
> kmodstat
2>&1
322 echo "#" > network
-statistics
323 echo "# arp -n -a" >> network
-statistics
324 echo "#" >> network
-statistics
325 arp
-n -a >> network
-statistics 2>&1
327 echo "#" >> network
-statistics
328 echo "# netstat -n -a -A" >> network
-statistics
329 echo "#" >> network
-statistics
330 netstat
-n -a -A >> network
-statistics 2>&1
332 echo "#" >> network
-statistics
333 echo "# netstat -s" >> network
-statistics
334 echo "#" >> network
-statistics
335 netstat
-s >> network
-statistics 2>&1
337 echo "#" >> network
-statistics
338 echo "# netstat -mmm" >> network
-statistics
339 echo "#" >> network
-statistics
340 netstat
-mmm >> network
-statistics 2>&1
342 echo "#" >> network
-statistics
343 echo "# netstat -i -n -d" >> network
-statistics
344 echo "#" >> network
-statistics
345 netstat
-i -n -d >> network
-statistics 2>&1
347 if [ -x /usr
/sbin
/ndp
]; then
348 echo "#" >> network
-statistics
349 echo "# ndp -n -a" >> network
-statistics
350 echo "#" >> network
-statistics
351 ndp
-n -a >> network
-statistics 2>&1
353 echo "#" >> network
-statistics
354 echo "# ndp -n -p" >> network
-statistics
355 echo "#" >> network
-statistics
356 ndp
-n -p >> network
-statistics 2>&1
358 echo "#" >> network
-statistics
359 echo "# ndp -n -r" >> network
-statistics
360 echo "#" >> network
-statistics
361 ndp
-n -r >> network
-statistics 2>&1
364 if [ -x /sbin
/ipfw
]; then
365 echo "#" >> network
-statistics
366 echo "# ipfw -at show" >> network
-statistics
367 echo "#" >> network
-statistics
368 ${PRIV} ipfw
-at show
>> network
-statistics 2>&1
371 if [ -x /sbin
/pfctl
]; then
373 echo "# pfctl -s all" >> pf
375 ${PRIV} pfctl
-s all
>> pf
2>&1
376 echo "==============================" >> pf
378 echo "# pfctl -s References" >> pf
380 ${PRIV} pfctl
-s References
>> pf
2>&1
381 for ANCHOR
in `pfctl -s Anchors 2>/dev/null`
383 echo "==============================" >> pf
385 echo "# pfctl -a ${ANCHOR} -s all" >> pf
387 ${PRIV} pfctl
-a ${ANCHOR} -s all
>> pf
2>&1
391 if [ -x /usr
/sbin
/lsof
]; then
392 echo "#" >> network
-statistics
393 echo "# lsof -i -U -n -P" >> network
-statistics
394 echo "#" >> network
-statistics
395 ${PRIV} lsof
-i -U -n -P >> network
-statistics 2>&1
399 # DirectoryService info
401 if [ -x /usr
/bin
/odutil
]; then
403 echo "# odutil show all" >> od-info
405 ${PRIV} odutil show all
>> od-info 2>&1
406 elif [ -x /usr
/bin
/dscacheutil
]; then
408 echo "# dscacheutil -configuration" >> ds
-info
410 dscacheutil
-configuration >> ds
-info 2>&1
413 echo "# dscacheutil -statistics" >> ds
-info
415 dscacheutil
-statistics >> ds
-info 2>&1
418 echo "# dscacheutil -cachedump -entries" >> ds
-info
420 dscacheutil
-cachedump -entries >> ds
-info 2>&1
424 # IPsec configuration
427 echo "# setkey -D" >> ipsec
431 if (/^(\s+[AE]:\s+\S+\s+)"?(.*)"?\s*$/) {
432 chop($sha1=`echo "$2" | openssl sha1`);
433 printf "%s[SHA-1:%s]\n", $1, $sha1;
441 echo "# setkey -Pp -D" >> ipsec
443 ${PRIV} setkey
-Pp -D >> ipsec
445 for CF
in /var
/run
/racoon
/*.conf
447 if [ ! -r "${CF}" ]; then
453 echo "# ${CF}" >> ipsec
457 if (/^(\s+shared_secret\s+use\s+)"?([^\s;"]+)"?(.*)/) {
458 chop($sha1=`echo "$2" | openssl sha1`);
459 printf "%s[SHA-1:%s]%s\n", $1, $sha1, $3;
467 # Kerberos configuration
469 if [ -x /usr
/bin
/klist
]; then
471 echo "# klist -e -c -A -f -a -n" >> kerberos
473 ${PRIV} klist
-e -c -A -f -a -n >> kerberos
2>&1
476 echo "# klist -e -k -t -K" >> kerberos
478 ${PRIV} klist
-e -k -t -K >> kerberos
2>&1
487 rm -f .btmmfifo .btmminfo .digsync
496 while nc
-6z ::1 "${PORT}" > /dev
/null
2>&1
498 BTMMPORT
=$((PORT + 1))
502 BTMM_CHECKMACDOTCOM
()
504 TAIL
=`echo "${1}" | cut -d. -f2-`
505 if [ "${TAIL}" = "members.mac.com" ]; then
513 # params: QUERYNAME QUERYTYPE
518 nc
-6 -l "${BTMMPORT}" < .btmmfifo \
519 | openssl s_client
-connect "${HOSTPORT}" -quiet > .btmmfifo
2>.digsync
&
522 while [ $N_RETRY -lt 50 -a ! -s .digsync
]
524 N_RETRY
=$((N_RETRY + 1))
528 dig @
::1 -p "${BTMMPORT}" \
532 "${1}" "${2}" 2>/dev
/null
537 # get the unique identifier used to lookup the keychain item for a zone
539 BTMM_UNIQUEIDFROMZONE
()
541 BTMM_CHECKMACDOTCOM
"${1}"
542 if [ $?
-eq 0 ]; then
549 # get hostname, port, TSIG name and TSIG data from keychain
553 ${PRIV} security
find-generic-password \
555 -g /Library
/Keychains
/System.keychain
> .btmminfo
2>/dev
/null
556 ${PRIV} security
find-generic-password \
558 -g /Library
/Keychains
/System.keychain \
560 | sed -n 's/^password: \"\(.*\)\"$/\1/p'
566 BTMM_CHECKMACDOTCOM
"${1}"
567 if [ $?
-eq 0 ]; then
568 echo "pm-members.mac.com.:443"
570 cat .btmminfo
| sed -n 's/.*0x00000007 <blob>=\"\(.*\)\"/\1/p'
576 BTMM_CHECKMACDOTCOM
"${1}"
577 if [ $?
-eq 0 ]; then
581 SECRET
=`BTMM_GETINFO "btmmrelay:${1}"`
583 if [ -z "${SECRET}" ]; then
584 echo " No Relay keychain item." >> btmm
588 if [ `echo "${SECRET}" | wc -l` -ne 1 ]; then
589 echo " More than one Relay keychain item." >> btmm
593 URLISH
=`BTMM_URLISH "${DOMAIN}"`
594 ACCOUNT
=`cat .btmminfo | sed -n 's/.*\"acct\"<blob>=\"\(.*\)\"/\1/p'`
595 KEYHASH
="[SHA-1:`echo ${SECRET} | openssl sha1`]"
596 echo " RHP: ${URLISH}" >> btmm
597 echo " RAC: ${ACCOUNT}" >> btmm
598 echo " RKY: ${KEYHASH}" >> btmm
606 echo "${DOMAIN}" >> btmm
608 DNSID
=`BTMM_UNIQUEIDFROMZONE "${DOMAIN}"`
609 SECRET
=`BTMM_GETINFO "${DNSID}"`
611 if [ -z "${SECRET}" ]; then
612 echo " No DNS keychain item." >> btmm
616 if [ `echo "${SECRET}" | wc -l` -ne 1 ]; then
617 echo " More than one DNS keychain item." >> btmm
621 URLISH
=`BTMM_URLISH "${DOMAIN}"`
622 HOSTPORT
=`echo "${URLISH}" | cut -d@ -f2`
623 ACCOUNT
=`cat .btmminfo | sed -n 's/.*\"acct\"<blob>=\"\(.*\)\"/\1/p'`
624 TSIG
="${ACCOUNT}:${SECRET}"
626 KEYHASH
="[SHA-1:`echo ${SECRET} | openssl sha1`]"
628 echo " DHP: ${URLISH}" >> btmm
629 echo " DAC: ${ACCOUNT}" >> btmm
630 echo " DKY: ${KEYHASH}" >> btmm
632 BTMM_RELAYINFO
"${DOMAIN}"
643 BTMM_DIG
"${TYPE}.${DOMAIN}" ptr \
647 /bin
/echo " ${REG}" >> btmm
650 INF_Q
=`/bin/echo "${REG}" | sed -e "s/${TYPE}/_device-info._tcp/"`
651 INF
=`BTMM_DIG "${INF_Q}" txt`
652 echo " INF: ${INF}" >> btmm
654 SRV
=`BTMM_DIG ${REG} srv`
655 SRV1
=`/bin/echo "${SRV}" | head -1`
656 echo " SRV: ${SRV1}" >> btmm
657 SRV2
=`/bin/echo "${SRV}" | tail +2`
658 if [ -n "${SRV2}" ]; then
660 /bin
/echo "${SRV2}" \
661 | sed -e 's/^/ *****: /' >> btmm
664 TXT
=`BTMM_DIG ${REG} txt`
665 TXT1
=`/bin/echo "${TXT}" | head -1`
666 echo " TXT: ${TXT1}" >> btmm
667 TXT2
=`/bin/echo "${TXT}" | tail +2`
668 if [ -n "${TXT2}" ]; then
669 /bin
/echo "${TXT2}" \
670 | sed -e 's/^/ *****: /' >> btmm
673 HOST
=`/bin/echo "${SRV}" | cut -d ' ' -f 4-`
674 if [ -n "${HOST}" ]; then
675 V4
=`BTMM_DIG ${HOST} a`
676 V6
=`BTMM_DIG ${HOST} aaaa`
677 KRB
=`BTMM_DIG _kerberos.${HOST} txt`
678 TUN
=`BTMM_DIG _autotunnel._udp.${HOST} srv`
679 AT6
=`BTMM_DIG _autotunnel6.${HOST} aaaa`
687 if [ -n "${V4}" ]; then
688 echo " v4: ${V4}" >> btmm
690 if [ -n "${V6}" ]; then
691 echo " v6: ${V6}" >> btmm
693 if [ -n "${KRB}" ]; then
694 echo " KRB: ${KRB}" >> btmm
696 if [ -n "${TUN}" ]; then
697 echo " TUN: ${TUN}" >> btmm
699 HOST
=`/bin/echo "${TUN}" | cut -d ' ' -f 4-`
700 if [ -n "${HOST}" ]; then
701 V4
=`BTMM_DIG ${HOST} a`
702 V6
=`BTMM_DIG ${HOST} aaaa`
704 if [ -n "${V4}" ]; then
705 echo " v4: ${V4}" >> btmm
707 if [ -n "${V6}" ]; then
708 echo " v6: ${V6}" >> btmm
711 if [ -n "${AT6}" ]; then
712 echo " AT6: ${AT6}" >> btmm
720 scutil
<<_END_OF_INPUT \
721 | sed -n 's@.* : *\(.*\)$@\1@p' \
725 show Setup:/Network/BackToMyMac
729 BTMM_REPORTZONE
"$DOMAIN"
735 # collect crash reports
742 mDNSResponderHelper \
751 /bin
/ls -1 /Library
/Logs
/DiagnosticReports
/${daemon}_
*.crash \
752 /Library
/Logs
/CrashReporter
/${daemon}_
*.crash \
756 if [ -f "${log}" ]; then
757 b
="`basename ${log}`"
758 ${PRIV} cat "${log}" > "${b}" 2>&1
764 # system usage statistics
766 echo "#" > system
-statistics
767 echo "# uptime" >> system
-statistics
768 echo "#" >> system
-statistics
769 uptime
>> system
-statistics 2>&1
771 echo "#" >> system
-statistics
772 echo "# sysctl -a" >> system
-statistics
773 echo "#" >> system
-statistics
774 sysctl
-a >> system
-statistics 2>&1
776 echo "#" >> system
-statistics
777 echo "# zprint" >> system
-statistics
778 echo "#" >> system
-statistics
779 zprint
>> system
-statistics 2>&1
781 echo "#" >> system
-statistics
782 echo "# top -l5 -s2" >> system
-statistics
783 echo "#" >> system
-statistics
785 echo "Please wait, collecting statistics"
787 top
-s 2 -l 5 >> system
-statistics 2>&1
790 # collect everything into a single archive
793 if [ -x /usr
/bin
/tar ]; then
794 tar -c ${GZ_OPT} -f "${ARCHIVE}" "${OUT}"
796 pax
-w ${GZ_OPT} -f "${ARCHIVE}" "${OUT}"
800 if [ ${UID} -eq 0 ]; then
801 if [ -n "${SUDO_UID}" -a -n "${SUDO_GID}" ]; then
802 if [ ${UID} -ne ${SUDO_UID} ]; then
803 chown
${SUDO_UID}:${SUDO_GID} "${ARCHIVE}"
808 echo "Network data collected to \"${ARCHIVE}\""
811 # if requested, generate a crash report
813 if [ "${OUTDIR}" = "/Library/Logs/CrashReporter/SystemConfiguration" -a "${1}" = "CRASH" ]; then