2 # Copyright (c) 2004-2012 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"
50 echo "Please wait, collecting information and statistics"
59 # network interface configuration
61 ifconfig
-a -L -b -m -r -v > ifconfig
2>&1
63 ifconfig
-a > ifconfig
2>&1
67 # network route configuration
69 netstat
-n -r -a -l > netstat
2>&1
74 for if in `ifconfig -l`
78 en
* ) ipconfig getpacket
${if} > ipconfig
-${if} 2>&1
86 if [ -x /System
/Library
/PrivateFrameworks
/Apple80211.framework
/Resources
/airport
]; then
87 /System
/Library
/PrivateFrameworks
/Apple80211.framework
/Resources
/airport
--getinfo \
94 if [ -e /System
/Library
/CoreServices
/SystemVersion.plist
]; then
95 cat /System
/Library
/CoreServices
/SystemVersion.plist \
96 > SystemVersion.plist
2>&1
98 if [ -e /System
/Library
/CoreServices
/ServerVersion.plist
]; then
99 cat /System
/Library
/CoreServices
/ServerVersion.plist \
100 > ServerVersion.plist
2>&1
106 ioreg
-i -l -w 0 > ioreg
2>&1
107 ioreg
-i -l -p IODeviceTree
-w 0 >> ioreg
2>&1
110 # Power Management info
113 echo "# pmset -g" >> pmset
115 pmset
-g >> pmset
2>&1
118 echo "# pmset -g ps" >> pmset
120 pmset
-g ps
>> pmset
2>&1
123 echo "# pmset -g assertions" >> pmset
125 pmset
-g assertions
>> pmset
2>&1
128 echo "# pmset -g log" >> pmset
130 pmset
-g log
| tail -n 25000 >> pmset
2>&1
135 hostname
> hostname
2>&1
140 hostinfo
> hostinfo
2>&1
141 if [ -e /etc
/hostconfig
]; then
142 cat /etc
/hostconfig
> etc.hostconfig
2>&1
148 scutil
--dns > dns
-configuration 2>&1
149 if [ -e /etc
/resolv.conf
]; then
150 cat /etc
/resolv.conf
> etc.resolv.conf
2>&1
152 if [ -e /var
/run
/resolv.conf
]; then
153 cat /var
/run
/resolv.conf
> var.run.resolv.conf
2>&1
157 # Proxy configuration
159 scutil
-d -v --proxy > proxy
-configuration 2>&1
162 # Network information
164 scutil
--nwi > network
-information 2>&1
167 # System / network preferences
170 /Library
/Preferences
/SystemConfiguration
/NetworkInterfaces.plist \
171 /Library
/Preferences
/SystemConfiguration
/com.apple.PowerManagement.plist \
172 /Library
/Preferences
/SystemConfiguration
/com.apple.airport.preferences.plist \
173 /Library
/Preferences
/SystemConfiguration
/com.apple.nat.plist \
174 /Library
/Preferences
/SystemConfiguration
/com.apple.smb.server.plist \
175 /Library
/Preferences
/SystemConfiguration
/com.apple.wifi.plist \
176 /Library
/Preferences
/SystemConfiguration
/preferences.plist \
177 /Library
/Preferences
/com.apple.alf.plist \
178 /Library
/Preferences
/com.apple.sharing.firewall.plist \
179 /Library
/Preferences
/com.apple.wwand.plist \
182 if [ -e "${f}" ]; then
184 cat "${f}" > "${b}" 2>&1
191 if [ -e /etc
/bootpd.plist
]; then
192 cat /etc
/bootpd.plist
> bootpd.plist
2>&1
193 cat /etc
/com.apple.named.proxy.conf
> com.apple.named.proxy.conf
2>/dev
/null
194 elif [ -e /Library
/Preferences
/SystemConfiguration
/bootpd.plist
]; then
195 cat /Library
/Preferences
/SystemConfiguration
/bootpd.plist
> bootpd.plist
2>&1
196 cat /Library
/Preferences
/SystemConfiguration
/com.apple.named.proxy.conf
> com.apple.named.proxy.conf
2>/dev
/null
202 ${PRIV} scutil
-p --snapshot
203 if [ -f /var
/tmp
/configd
-store.plist
]; then
204 cat /var
/tmp
/configd
-store.plist
> configd
-store.plist
2>&1
206 if [ -f /var
/tmp
/configd
-pattern.plist
]; then
207 cat /var
/tmp
/configd
-pattern.plist
> configd
-pattern.plist
2>&1
209 if [ -f /var
/tmp
/configd
-session.plist
]; then
210 cat /var
/tmp
/configd
-session.plist
> configd
-session.plist
2>&1
212 if [ -f /var
/tmp
/configd
-state ]; then
213 cat /var
/tmp
/configd
-state > configd
-state 2>&1
215 if [ -f /var
/tmp
/configd
-reachability ]; then
216 cat /var
/tmp
/configd
-reachability > configd
-reachability 2>&1
220 # network reachability
222 scutil
-d -v -r www.apple.com
"" no
-server > reachability
-info 2>&1
223 if [ -x /usr
/bin
/dig -a -f /etc
/resolv.conf
]; then
224 /usr
/bin
/dig -t any
-c any www.apple.com
> dig-results 2>/dev
/null
228 # mounted filesystems
230 mount
> mounted
-filesystems 2>&1
233 # mDNSResponder, networkd info
235 if [ -x /usr
/bin
/killall
]; then
236 ${PRIV} killall
-INFO mDNSResponder
237 ${PRIV} killall
-INFO networkd
239 # and wait a short amount of time for mDNSResponder
240 # to actually log the requested information
247 if [ -x /usr
/sbin
/awacsd
-a -x /usr
/bin
/killall
]; then
248 ${PRIV} killall
-INFO awacsd
2>/dev
/null
250 # and wait a short amount of time for awacsd
251 # to actually log the requested information
256 # system log, kernel.log, early boot log messages
258 if [ -x /usr
/bin
/syslog
]; then
259 # save the recent activity
260 ${PRIV} syslog
| tail -n 25000 > syslog
262 # save just the "kernel" activity (in case some of the
263 # interesting/relevant message are before the messages
265 ${PRIV} syslog
-k Facility kern
| tail -n 25000 > kernel
267 if [ -d /var
/log
/DiagnosticMessages
]; then
268 # save any MessageTracer activity
269 ${PRIV} syslog
-d /var
/log
/DiagnosticMessages \
272 | tail -n 25000 > DiagnosticMessages
275 if [ -f /var
/log
/system.log
]; then
276 ${PRIV} tail -n 25000 /var
/log
/system.log
> system.log
278 if [ -f /var
/log
/kernel.log
]; then
279 ${PRIV} tail -n 25000 /var
/log
/kernel.log
> kernel.log
282 ${PRIV} dmesg
> dmesg
285 # IPConfiguration log
287 if [ -f /var
/log
/com.apple.IPConfiguration.bootp
]; then
288 ${PRIV} tail -n 2000 /var
/log
/com.apple.IPConfiguration.bootp \
289 > com.apple.IPConfiguration.bootp
295 scutil
<<_END_OF_INPUT \
299 if (index($2, "/") == 1) { print $2 } \
300 else { print "/var/log/ppp/" $2 } \
303 print "/tmp/pppotcp.log" \
309 show Setup:/Network/Service/[^/]+/PPP pattern
313 if [ -f "${logFile}" ]; then
314 b
="`basename ${logFile}`"
315 cat "${logFile}" > "${b}" 2>&1
320 # application firewall log
322 if [ -f /var
/log
/appfirewall.log
]; then
323 ${PRIV} tail -n 2000 /var
/log
/appfirewall.log
> appfirewall.log
327 # kernel extensions statistic
329 if [ -x /usr
/sbin
/kextstat
]; then
330 kextstat
> kextstat
2>&1
331 elif [ -x /usr
/sbin
/kmodstat
]; then
332 kmodstat
> kmodstat
2>&1
338 echo "#" > network
-statistics
339 echo "# arp -n -a" >> network
-statistics
340 echo "#" >> network
-statistics
341 arp
-n -a >> network
-statistics 2>&1
343 echo "#" >> network
-statistics
344 echo "# netstat -n -a -A" >> network
-statistics
345 echo "#" >> network
-statistics
346 netstat
-n -a -A >> network
-statistics 2>&1
348 echo "#" >> network
-statistics
349 echo "# netstat -s" >> network
-statistics
350 echo "#" >> network
-statistics
351 netstat
-s >> network
-statistics 2>&1
353 echo "#" >> network
-statistics
354 echo "# netstat -mmm" >> network
-statistics
355 echo "#" >> network
-statistics
356 netstat
-mmm >> network
-statistics 2>&1
358 echo "#" >> network
-statistics
359 echo "# netstat -i -n -d" >> network
-statistics
360 echo "#" >> network
-statistics
361 netstat
-i -n -d >> network
-statistics 2>&1
363 echo "#" >> network
-statistics
364 echo "# netstat -g -n -s" >> network
-statistics
365 echo "#" >> network
-statistics
366 netstat
-g -n -s >> network
-statistics 2>&1
368 if [ -x /usr
/sbin
/ndp
]; then
369 echo "#" >> network
-statistics
370 echo "# ndp -n -a" >> network
-statistics
371 echo "#" >> network
-statistics
372 ndp
-n -a >> network
-statistics 2>&1
374 echo "#" >> network
-statistics
375 echo "# ndp -n -p" >> network
-statistics
376 echo "#" >> network
-statistics
377 ndp
-n -p >> network
-statistics 2>&1
379 echo "#" >> network
-statistics
380 echo "# ndp -n -r" >> network
-statistics
381 echo "#" >> network
-statistics
382 ndp
-n -r >> network
-statistics 2>&1
384 for if in `ifconfig -l`
386 echo "#" >> network
-statistics
387 echo "# ndp -i ${if}" >> network
-statistics
388 echo "#" >> network
-statistics
389 ndp
-i ${if} >> network
-statistics 2>&1
393 if [ -x /sbin
/ipfw
]; then
394 echo "#" >> network
-statistics
395 echo "# ipfw -at show" >> network
-statistics
396 echo "#" >> network
-statistics
397 ${PRIV} ipfw
-at show
>> network
-statistics 2>&1
400 if [ -x /sbin
/ip6fw
]; then
401 echo "#" >> network
-statistics
402 echo "# ip6fw -at show" >> network
-statistics
403 echo "#" >> network
-statistics
404 ${PRIV} ip6fw
-at show
>> network
-statistics 2>&1
407 if [ -x /sbin
/pfctl
]; then
409 echo "# pfctl -s all" >> pf
411 ${PRIV} pfctl
-s all
>> pf
2>&1
412 echo "==============================" >> pf
414 echo "# pfctl -s References" >> pf
416 ${PRIV} pfctl
-s References
>> pf
2>&1
417 for ANCHOR
in `${PRIV} pfctl -s Anchors -v 2>/dev/null`
419 echo "==============================" >> pf
421 echo "# pfctl -a ${ANCHOR} -s all" >> pf
423 ${PRIV} pfctl
-a ${ANCHOR} -s all
>> pf
2>&1
427 if [ -x /usr
/sbin
/lsof
]; then
428 echo "#" >> network
-statistics
429 echo "# lsof -i -U -n -P" >> network
-statistics
430 echo "#" >> network
-statistics
431 ${PRIV} lsof
-i -U -n -P >> network
-statistics 2>&1
435 # DirectoryService info
437 if [ -x /usr
/bin
/odutil
]; then
439 echo "# odutil show all" >> od-info
441 ${PRIV} odutil show all
>> od-info 2>&1
442 elif [ -x /usr
/bin
/dscacheutil
]; then
444 echo "# dscacheutil -configuration" >> ds
-info
446 dscacheutil
-configuration >> ds
-info 2>&1
449 echo "# dscacheutil -statistics" >> ds
-info
451 dscacheutil
-statistics >> ds
-info 2>&1
454 echo "# dscacheutil -cachedump -entries" >> ds
-info
456 dscacheutil
-cachedump -entries >> ds
-info 2>&1
460 # IPsec configuration
463 echo "# setkey -D" >> ipsec
466 | perl
-M'Digest::MD5 qw(md5_hex)' -l -n -e '
467 if (/^(\s+[AE]:\s+\S+\s+)"?(.*)"?\s*$/) {
468 printf "%s[MD5:%s]%s\n", $1, md5_hex($2 . "\n"), $3;
476 echo "# setkey -Pp -D" >> ipsec
478 ${PRIV} setkey
-Pp -D >> ipsec
480 for CF
in /var
/run
/racoon
/*.conf
482 if [ ! -r "${CF}" ]; then
488 echo "# ${CF}" >> ipsec
491 | perl
-M'Digest::MD5 qw(md5_hex)' -l -n -e '
492 if (/^(\s+shared_secret\s+use\s+)"?([^\s;"]+)"?(.*)/) {
493 printf "%s[MD5:%s]%s\n", $1, md5_hex($2 . "\n"), $3;
501 # Kerberos configuration
503 if [ -x /usr
/bin
/klist
]; then
505 echo "# klist -e -c -A -f -a -n" >> kerberos
507 ${PRIV} klist
-e -c -A -f -a -n >> kerberos
2>&1
510 echo "# klist -e -k -t -K" >> kerberos
512 ${PRIV} klist
-e -k -t -K >> kerberos
2>&1
521 rm -f .btmmfifo .btmminfo .digsync
530 while nc
-6z ::1 "${PORT}" > /dev
/null
2>&1
532 BTMMPORT
=$((PORT + 1))
536 BTMM_CHECKMACDOTCOM
()
538 TAIL
=`echo "${1}" | cut -d. -f2-`
539 if [ "${TAIL}" = "members.mac.com" ]; then
547 # params: QUERYNAME QUERYTYPE
552 nc
-6 -l "${BTMMPORT}" < .btmmfifo \
553 | openssl s_client
-connect "${HOSTPORT}" -quiet > .btmmfifo
2>.digsync
&
556 while [ $N_RETRY -lt 50 -a ! -s .digsync
]
558 N_RETRY
=$((N_RETRY + 1))
562 dig @
::1 -p "${BTMMPORT}" \
566 "${1}" "${2}" 2>/dev
/null
571 # get the unique identifier used to lookup the keychain item for a zone
573 BTMM_UNIQUEIDFROMZONE
()
575 BTMM_CHECKMACDOTCOM
"${1}"
576 if [ $?
-eq 0 ]; then
583 # get hostname, port, TSIG name and TSIG data from keychain
587 ${PRIV} security
find-generic-password \
589 -g /Library
/Keychains
/System.keychain
> .btmminfo
2>/dev
/null
590 ${PRIV} security
find-generic-password \
592 -g /Library
/Keychains
/System.keychain \
594 | sed -n 's/^password: \"\(.*\)\"$/\1/p'
600 BTMM_CHECKMACDOTCOM
"${1}"
601 if [ $?
-eq 0 ]; then
602 echo "pm-members.mac.com.:443"
604 cat .btmminfo
| sed -n 's/.*0x00000007 <blob>=\"\(.*\)\"/\1/p'
610 BTMM_CHECKMACDOTCOM
"${1}"
611 if [ $?
-eq 0 ]; then
615 SECRET
=`BTMM_GETINFO "btmmrelay:${1}"`
617 if [ -z "${SECRET}" ]; then
618 echo " No Relay keychain item." >> btmm
622 if [ `echo "${SECRET}" | wc -l` -ne 1 ]; then
623 echo " More than one Relay keychain item." >> btmm
627 URLISH
=`BTMM_URLISH "${DOMAIN}"`
628 ACCOUNT
=`cat .btmminfo | sed -n 's/.*\"acct\"<blob>=\"\(.*\)\"/\1/p'`
629 KEYHASH
="`perl -M'Digest::SHA1 qw(sha1_hex)' -l -e '
630 printf "[SHA1
:%s
]\n", sha1_hex($ARGV[0] . "\n");
632 echo " RHP: ${URLISH}" >> btmm
633 echo " RAC: ${ACCOUNT}" >> btmm
634 echo " RKY: ${KEYHASH}" >> btmm
642 echo "${DOMAIN}" >> btmm
644 DNSID
=`BTMM_UNIQUEIDFROMZONE "${DOMAIN}"`
645 SECRET
=`BTMM_GETINFO "${DNSID}"`
647 if [ -z "${SECRET}" ]; then
648 echo " No DNS keychain item." >> btmm
652 if [ `echo "${SECRET}" | wc -l` -ne 1 ]; then
653 echo " More than one DNS keychain item." >> btmm
657 URLISH
=`BTMM_URLISH "${DOMAIN}"`
658 HOSTPORT
=`echo "${URLISH}" | cut -d@ -f2`
659 ACCOUNT
=`cat .btmminfo | sed -n 's/.*\"acct\"<blob>=\"\(.*\)\"/\1/p'`
660 TSIG
="${ACCOUNT}:${SECRET}"
662 KEYHASH
="`perl -M'Digest::SHA1 qw(sha1_hex)' -l -e '
663 printf "[SHA1
:%s
]\n", sha1_hex($ARGV[0] . "\n");
666 echo " DHP: ${URLISH}" >> btmm
667 echo " DAC: ${ACCOUNT}" >> btmm
668 echo " DKY: ${KEYHASH}" >> btmm
670 BTMM_RELAYINFO
"${DOMAIN}"
672 REACHHOST
=`echo "${HOSTPORT}" | cut -d: -f1`
673 STATUSES
=`scutil -r "${REACHHOST}"`
674 for REACHSTATUS
in `echo ${STATUSES} | tr -d ' ' | tr ',' ' '`; do
675 if [ "$REACHSTATUS" == "NotReachable" ] \
676 || [ "$REACHSTATUS" == "ConnectionRequired" ]; then
677 echo " Skipping DNS queries, no connectivity" >> btmm
691 BTMM_DIG
"${TYPE}.${DOMAIN}" ptr \
695 /bin
/echo " ${REG}" >> btmm
698 INF_Q
=`/bin/echo "${REG}" | sed -e "s/${TYPE}/_device-info._tcp/"`
699 INF
=`BTMM_DIG "${INF_Q}" txt`
700 echo " INF: ${INF}" >> btmm
702 SRV
=`BTMM_DIG ${REG} srv`
703 SRV1
=`/bin/echo "${SRV}" | head -1`
704 echo " SRV: ${SRV1}" >> btmm
705 SRV2
=`/bin/echo "${SRV}" | tail +2`
706 if [ -n "${SRV2}" ]; then
708 /bin
/echo "${SRV2}" \
709 | sed -e 's/^/ *****: /' >> btmm
712 TXT
=`BTMM_DIG ${REG} txt`
713 TXT1
=`/bin/echo "${TXT}" | head -1`
714 echo " TXT: ${TXT1}" >> btmm
715 TXT2
=`/bin/echo "${TXT}" | tail +2`
716 if [ -n "${TXT2}" ]; then
717 /bin
/echo "${TXT2}" \
718 | sed -e 's/^/ *****: /' >> btmm
721 HOST
=`/bin/echo "${SRV}" | cut -d ' ' -f 4-`
722 if [ -n "${HOST}" ]; then
723 V4
=`BTMM_DIG ${HOST} a`
724 V6
=`BTMM_DIG ${HOST} aaaa`
725 KRB
=`BTMM_DIG _kerberos.${HOST} txt`
726 TUN
=`BTMM_DIG _autotunnel._udp.${HOST} srv`
727 AT6
=`BTMM_DIG _autotunnel6.${HOST} aaaa`
735 if [ -n "${V4}" ]; then
736 echo " v4: ${V4}" >> btmm
738 if [ -n "${V6}" ]; then
739 echo " v6: ${V6}" >> btmm
741 if [ -n "${KRB}" ]; then
742 echo " KRB: ${KRB}" >> btmm
744 if [ -n "${TUN}" ]; then
745 echo " TUN: ${TUN}" >> btmm
747 HOST
=`/bin/echo "${TUN}" | cut -d ' ' -f 4-`
748 if [ -n "${HOST}" ]; then
749 V4
=`BTMM_DIG ${HOST} a`
750 V6
=`BTMM_DIG ${HOST} aaaa`
752 if [ -n "${V4}" ]; then
753 echo " v4: ${V4}" >> btmm
755 if [ -n "${V6}" ]; then
756 echo " v6: ${V6}" >> btmm
759 if [ -n "${AT6}" ]; then
760 echo " AT6: ${AT6}" >> btmm
768 scutil
<<_END_OF_INPUT \
769 | sed -n 's@.* : *\(.*\)$@\1@p' \
773 show Setup:/Network/BackToMyMac
777 BTMM_REPORTZONE
"$DOMAIN"
783 # collect crash reports
790 mDNSResponderHelper \
800 /bin
/ls -1 /Library
/Logs
/DiagnosticReports
/${daemon}_
*.crash \
801 /Library
/Logs
/CrashReporter
/${daemon}_
*.crash \
802 /Library
/Logs
/CrashReporter
/${daemon}_
*.plist \
806 if [ -f "${log}" ]; then
807 b
="`basename ${log}`"
808 ${PRIV} cat "${log}" > "${b}" 2>&1
816 if [ -x /usr
/sbin
/system_profiler
]; then
817 system_profiler
-xml SPEthernetDataType \
818 SPFibreChannelDataType \
823 SPThunderboltDataType \
825 SPAirPortDataType
> system_profiler.spx
2>&1
829 # system usage statistics
831 echo "#" > system
-statistics
832 echo "# uptime" >> system
-statistics
833 echo "#" >> system
-statistics
834 uptime
>> system
-statistics 2>&1
836 echo "#" >> system
-statistics
837 echo "# sysctl -a" >> system
-statistics
838 echo "#" >> system
-statistics
839 sysctl
-a >> system
-statistics 2>&1
841 echo "#" >> system
-statistics
842 echo "# zprint" >> system
-statistics
843 echo "#" >> system
-statistics
844 zprint
>> system
-statistics 2>&1
846 echo "#" >> system
-statistics
847 echo "# top -l5 -s2" >> system
-statistics
848 echo "#" >> system
-statistics
849 top
-s 2 -l 5 >> system
-statistics 2>&1
852 # collect everything into a single archive
855 if [ -x /usr
/bin
/tar ]; then
856 tar -c ${GZ_OPT} -f "${ARCHIVE}" "${OUT}"
858 pax
-w ${GZ_OPT} -f "${ARCHIVE}" "${OUT}"
862 if [ ${UID} -eq 0 ]; then
863 if [ -n "${SUDO_UID}" -a -n "${SUDO_GID}" ]; then
864 if [ ${UID} -ne ${SUDO_UID} ]; then
865 chown
${SUDO_UID}:${SUDO_GID} "${ARCHIVE}"
870 echo "Network data collected to \"${ARCHIVE}\""
873 # if requested, generate a crash report
875 if [ "${OUTDIR}" = "/Library/Logs/CrashReporter/SystemConfiguration" -a "${1}" = "CRASH" ]; then