]> git.saurik.com Git - apple/configd.git/blob - get-mobility-info
configd-293.6.tar.gz
[apple/configd.git] / get-mobility-info
1 #!/bin/sh
2 # Copyright (c) 2004-2009 Apple Inc.
3 #
4 # get-mobility-info
5 #
6 # Collect system & network configuration information.
7 #
8
9 PATH=/bin:/usr/bin:/sbin:/usr/sbin
10
11 PRIV=""
12 if [ ${EUID} -ne 0 ]; then
13 PRIV="sudo"
14 fi
15
16 OUT="mobility-info-`date +'%m.%d.%Y.%H%M%S'`"
17 OUTDIR="/var/tmp"
18 if [ -d ~/Desktop ]; then
19 OUTDIR=~/Desktop
20 elif [ "`readlink /tmp`" = "private/var/tmp" ]; then
21 OUTDIR=/Library/Logs/CrashReporter/SystemConfiguration
22 mkdir -p ${OUTDIR}
23 fi
24
25 umask 077
26
27 WORKDIR=`mktemp -d -q "/tmp/${OUT}"`
28 if [ $? -ne 0 ]; then
29 echo "Could not create snapshot directory"
30 exit 1
31 fi
32
33 GZ_EXT=""
34 GZ_OPT=""
35 if [ -x /usr/bin/gzip ]; then
36 GZ_EXT=".gz"
37 GZ_OPT="-z"
38 fi
39
40 ARCHIVE=`mktemp -q "${OUTDIR}/${OUT}.tar${GZ_EXT}"`
41 if [ $? -ne 0 ]; then
42 echo "Could not create snapshot archive"
43 rm -rf "${WORKDIR}"
44 exit 1
45 fi
46
47 cd "${WORKDIR}"
48
49 #
50 # processes
51 #
52 ps axlww > ps 2>&1
53
54 #
55 # network interface configuration
56 #
57 ifconfig -a -b > ifconfig 2>&1
58
59 #
60 # network route configuration
61 #
62 netstat -n -r -a -l > netstat 2>&1
63
64 #
65 # DHCP configuration
66 #
67 for if in `ifconfig -l`
68 do
69 case ${if} in
70 lo* ) ;;
71 en* ) ipconfig getpacket ${if} > ipconfig-${if} 2>&1
72 ;;
73 esac
74 done
75
76 #
77 # AirPort info
78 #
79 if [ -x /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport ]; then
80 /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport --getinfo \
81 > airport 2>&1
82 fi
83
84 #
85 # OS info
86 #
87 if [ -e /System/Library/CoreServices/SystemVersion.plist ]; then
88 cat /System/Library/CoreServices/SystemVersion.plist \
89 > SystemVersion.plist 2>&1
90 fi
91 if [ -e /System/Library/CoreServices/ServerVersion.plist ]; then
92 cat /System/Library/CoreServices/ServerVersion.plist \
93 > ServerVersion.plist 2>&1
94 fi
95
96 #
97 # IOKit info
98 #
99 ioreg -i -l -w 0 > ioreg 2>&1
100 ioreg -i -l -p IODeviceTree -w 0 >> ioreg 2>&1
101
102 #
103 # Host name
104 #
105 hostname > hostname 2>&1
106
107 #
108 # Host configuration
109 #
110 hostinfo > hostinfo 2>&1
111 if [ -e /etc/hostconfig ]; then
112 cat /etc/hostconfig > etc.hostconfig 2>&1
113 fi
114
115 #
116 # DNS configuration
117 #
118 scutil --dns > dns-configuration 2>&1
119 if [ -e /etc/resolv.conf ]; then
120 cat /etc/resolv.conf > etc.resolv.conf 2>&1
121 fi
122 if [ -e /var/run/resolv.conf ]; then
123 cat /var/run/resolv.conf > var.run.resolv.conf 2>&1
124 fi
125
126 #
127 # Proxy configuration
128 #
129 scutil --proxy > proxy-configuration 2>&1
130
131 #
132 # System / network preferences
133 #
134 for f in \
135 /Library/Preferences/SystemConfiguration/NetworkInterfaces.plist \
136 /Library/Preferences/SystemConfiguration/com.apple.PowerManagement.plist \
137 /Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist \
138 /Library/Preferences/SystemConfiguration/com.apple.nat.plist \
139 /Library/Preferences/SystemConfiguration/com.apple.network.identification.plist \
140 /Library/Preferences/SystemConfiguration/com.apple.smb.server.plist \
141 /Library/Preferences/SystemConfiguration/com.apple.wifi.plist \
142 /Library/Preferences/SystemConfiguration/preferences.plist \
143 /Library/Preferences/com.apple.alf.plist \
144 /Library/Preferences/com.apple.sharing.firewall.plist \
145
146 do
147 if [ -e "${f}" ]; then
148 b="`basename ${f}`"
149 cat "${f}" > "${b}" 2>&1
150 fi
151 done
152
153 #
154 # configd's cache
155 #
156 ${PRIV} scutil -p <<_END_OF_INPUT
157 open
158 snapshot
159 quit
160 _END_OF_INPUT
161 if [ -f /var/tmp/configd-store.xml ]; then
162 cat /var/tmp/configd-store.xml > configd-store.xml 2>&1
163 fi
164 if [ -f /var/tmp/configd-pattern.xml ]; then
165 cat /var/tmp/configd-pattern.xml > configd-pattern.xml 2>&1
166 fi
167 if [ -f /var/tmp/configd-session.xml ]; then
168 cat /var/tmp/configd-session.xml > configd-session.xml 2>&1
169 fi
170 if [ -f /var/tmp/configd-state ]; then
171 cat /var/tmp/configd-state > configd-state 2>&1
172 fi
173
174 #
175 # network reachability
176 #
177 scutil -d -v -r www.apple.com > reachability-info 2>&1
178 if [ -x /usr/bin/dig -a -f /etc/resolv.conf ]; then
179 /usr/bin/dig -t any -c any www.apple.com > dig-results 2>/dev/null
180 fi
181
182 #
183 # mounted filesystems
184 #
185 mount > mounted-filesystems 2>&1
186
187 #
188 # mDNSResponder info
189 #
190 if [ -f /var/run/mDNSResponder.pid ]; then
191 ${PRIV} kill -INFO `cat /var/run/mDNSResponder.pid`
192 fi
193
194 #
195 # system log, kernel.log, early boot log messages
196 #
197 if [ -x /usr/bin/syslog ]; then
198 ${PRIV} syslog | tail -n 25000 > syslog
199 if [ -d /var/log/DiagnosticMessages ]; then
200 ${PRIV} syslog -d /var/log/DiagnosticMessages \
201 -F raw \
202 -T local \
203 | tail -n 25000 > DiagnosticMessages
204 fi
205 else
206 if [ -f /var/log/system.log ]; then
207 ${PRIV} tail -n 25000 /var/log/system.log > system.log
208 fi
209 if [ -f /var/log/kernel.log ]; then
210 ${PRIV} tail -n 25000 /var/log/kernel.log > kernel.log
211 fi
212 fi
213 ${PRIV} dmesg > dmesg
214
215 #
216 # IPConfiguration log
217 #
218 if [ -f /var/log/com.apple.IPConfiguration.bootp ]; then
219 ${PRIV} tail -n 2000 /var/log/com.apple.IPConfiguration.bootp \
220 > com.apple.IPConfiguration.bootp
221 fi
222
223 #
224 # ppp log file(s)
225 #
226 scutil <<_END_OF_INPUT \
227 | awk -F' *: *' \
228 ' \
229 /Logfile : / { \
230 if (index($2, "/") == 1) { print $2 } \
231 else { print "/var/log/ppp/" $2 } \
232 } \
233 END { \
234 print "/tmp/pppotcp.log" \
235 } \
236 ' \
237 | sort -u \
238 | while read logFile
239 open
240 show Setup:/Network/Service/[^/]+/PPP pattern
241 quit
242 _END_OF_INPUT
243 do
244 if [ -f "${logFile}" ]; then
245 b="`basename ${logFile}`"
246 cat "${logFile}" > "${b}" 2>&1
247 fi
248 done
249
250 #
251 # application firewall log
252 #
253 if [ -f /var/log/appfirewall.log ]; then
254 ${PRIV} tail -n 2000 /var/log/appfirewall.log > appfirewall.log
255 fi
256
257 #
258 # kernel extensions statistic
259 #
260 if [ -x /usr/sbin/kextstat ]; then
261 kextstat > kextstat 2>&1
262 elif [ -x /usr/sbin/kmodstat ]; then
263 kmodstat > kmodstat 2>&1
264 fi
265
266 #
267 # network statistics
268 #
269 echo "#" > network-statistics
270 echo "# arp -n -a" >> network-statistics
271 echo "#" >> network-statistics
272 arp -n -a >> network-statistics 2>&1
273
274 echo "#" >> network-statistics
275 echo "# netstat -n -a -A" >> network-statistics
276 echo "#" >> network-statistics
277 netstat -n -a -A >> network-statistics 2>&1
278
279 if [ -x /usr/sbin/lsof ]; then
280 echo "#" >> network-statistics
281 echo "# lsof -i -n -P" >> network-statistics
282 echo "#" >> network-statistics
283 ${PRIV} lsof -i -n -P >> network-statistics 2>&1
284 fi
285
286 echo "#" >> network-statistics
287 echo "# netstat -s" >> network-statistics
288 echo "#" >> network-statistics
289 netstat -s >> network-statistics 2>&1
290
291 echo "#" >> network-statistics
292 echo "# netstat -mmm" >> network-statistics
293 echo "#" >> network-statistics
294 netstat -mmm >> network-statistics 2>&1
295
296 echo "#" >> network-statistics
297 echo "# netstat -i -n -d" >> network-statistics
298 echo "#" >> network-statistics
299 netstat -i -n -d >> network-statistics 2>&1
300
301 if [ -x /sbin/ipfw ]; then
302 echo "#" >> network-statistics
303 echo "# ipfw -at show" >> network-statistics
304 echo "#" >> network-statistics
305 ipfw -at show >> network-statistics 2>&1
306 fi
307
308 if [ -x /usr/sbin/appletalk ]; then
309 echo "#" >> network-statistics
310 echo "# appletalk -s" >> network-statistics
311 echo "#" >> network-statistics
312 appletalk -s >> network-statistics 2>&1
313 fi
314
315 #
316 # system usage statistics
317 #
318 echo "#" > system-statistics
319 echo "# uptime" >> system-statistics
320 echo "#" >> system-statistics
321 uptime >> system-statistics 2>&1
322
323 echo "#" >> system-statistics
324 echo "# sysctl -a" >> system-statistics
325 echo "#" >> system-statistics
326 sysctl -a >> system-statistics 2>&1
327
328 echo "#" >> system-statistics
329 echo "# zprint" >> system-statistics
330 echo "#" >> system-statistics
331 zprint >> system-statistics 2>&1
332
333 echo "#" >> system-statistics
334 echo "# top -l5 -s2" >> system-statistics
335 echo "#" >> system-statistics
336 echo ""
337 echo "Please wait, collecting statistics"
338 echo ""
339 top -s 2 -l 5 >> system-statistics 2>&1
340
341 #
342 # DirectoryService info
343 #
344 if [ -x /usr/bin/dscacheutil ]; then
345 echo "#" > ds-info
346 echo "# dscacheutil -configuration" >> ds-info
347 echo "#" >> ds-info
348 dscacheutil -configuration >> ds-info 2>&1
349
350 echo "#" >> ds-info
351 echo "# dscacheutil -statistics" >> ds-info
352 echo "#" >> ds-info
353 dscacheutil -statistics >> ds-info 2>&1
354
355 echo "#" >> ds-info
356 echo "# dscacheutil -cachedump -entries" >> ds-info
357 echo "#" >> ds-info
358 dscacheutil -cachedump -entries >> ds-info 2>&1
359 fi
360
361 #
362 # IPsec configuration
363 #
364 echo "#" > ipsec
365 echo "# setkey -D" >> ipsec
366 echo "#" >> ipsec
367 ${PRIV} setkey -D \
368 | perl -nle '
369 if (/^(\s+[AE]:\s+\S+\s+)"?(.*)"?\s*$/) {
370 chop($sha1=`echo "$2" | openssl sha1`);
371 printf "%s[SHA-1:%s]\n", $1, $sha1;
372 } else {
373 printf "%s\n", $_;
374 }
375 ' >> ipsec
376
377 echo "" >> ipsec
378 echo "#" >> ipsec
379 echo "# setkey -Pp -D" >> ipsec
380 echo "#" >> ipsec
381 ${PRIV} setkey -Pp -D >> ipsec
382
383 for CF in /var/run/racoon/*.conf
384 do
385 if [ ! -r "${CF}" ]; then
386 continue
387 fi
388
389 echo "" >> ipsec
390 echo "#" >> ipsec
391 echo "# ${CF}" >> ipsec
392 echo "#" >> ipsec
393 ${PRIV} cat ${CF} \
394 | perl -nle '
395 if (/^(\s+shared_secret\s+use\s+)"?([^\s;"]+)"?(.*)/) {
396 chop($sha1=`echo "$2" | openssl sha1`);
397 printf "%s[SHA-1:%s]%s\n", $1, $sha1, $3;
398 } else {
399 printf "%s\n", $_;
400 }
401 ' >> ipsec
402 done
403
404 #
405 # Kerberos configuration
406 #
407 if [ -x /usr/bin/klist ]; then
408 echo "#" > kerberos
409 echo "# klist -e -c -A -f -a -n" >> kerberos
410 echo "#" >> kerberos
411 ${PRIV} klist -e -c -A -f -a -n >> kerberos 2>&1
412
413 echo "#" >> kerberos
414 echo "# klist -e -k -t -K" >> kerberos
415 echo "#" >> kerberos
416 ${PRIV} klist -e -k -t -K >> kerberos 2>&1
417 fi
418
419 #
420 # BTMM configuration
421 #
422 DIG()
423 {
424 /usr/bin/dig @pm-members.mac.com -y "${DOMAIN}:${TSIG}" +short "${1}" "${2}" 2>/dev/null
425 }
426
427 scutil <<_END_OF_INPUT \
428 | sed -n 's@.* : *\(.*\.members\.mac\.com\)$@\1@p' \
429 | sort \
430 | while read DOMAIN
431 open
432 show Setup:/Network/BackToMyMac
433 quit
434 _END_OF_INPUT
435 do
436 echo "" >> btmm
437 echo "${DOMAIN}" >> btmm
438
439 # lookup TSIG in base64 format
440 TSIG=` \
441 ${PRIV} security find-generic-password \
442 -s dns:${DOMAIN} \
443 -g /Library/Keychains/System.keychain 2>&1 \
444 | grep "^password: " \
445 | cut -d '"' -f 2 \
446 | cut -d '\' -f 1 \
447 `
448 if [ -z "$TSIG" ]; then
449 echo " No TSIG in system keychain." >> btmm
450 continue
451 fi
452 if [ `echo "$TSIG" | wc -l` -ne 1 ] ; then
453 echo " More than one TSIG in system keychain." >> btmm
454 continue
455 fi
456
457 KEYHASH="[SHA-1:`echo ${TSIG} | openssl sha1`]"
458 echo "" >> btmm
459 echo " KEY: ${KEYHASH}" >> btmm
460
461 for TYPE in \
462 _afpovertcp._tcp \
463 _airport._tcp \
464 _adisk._tcp \
465 _http._tcp \
466 _rfb._tcp \
467 _smb._tcp \
468 _ssh._tcp
469 do
470 DIG "${TYPE}.${DOMAIN}" ptr \
471 | while read -r REG
472 do
473 echo "" >> btmm
474 /bin/echo " ${REG}" >> btmm
475 echo "" >> btmm
476
477 INF_Q=`/bin/echo "${REG}" | sed -e "s/${TYPE}/_device-info._tcp/"`
478 INF=`DIG "${INF_Q}" txt`
479 echo " INF: ${INF}" >> btmm
480
481 SRV=`DIG ${REG} srv`
482 SRV1=`/bin/echo "${SRV}" | head -1`
483 echo " SRV: ${SRV1}" >> btmm
484 SRV2=`/bin/echo "${SRV}" | tail +2`
485 if [ -n "${SRV2}" ]; then
486 SRV="${SRV1}"
487 /bin/echo "${SRV2}" \
488 | sed -e 's/^/ *****: /' >> btmm
489 fi
490
491 TXT=`DIG ${REG} txt`
492 TXT1=`/bin/echo "${TXT}" | head -1`
493 echo " TXT: ${TXT1}" >> btmm
494 TXT2=`/bin/echo "${TXT}" | tail +2`
495 if [ -n "${TXT2}" ]; then
496 /bin/echo "${TXT2}" \
497 | sed -e 's/^/ *****: /' >> btmm
498 fi
499
500 HOST=`/bin/echo "${SRV}" | cut -d ' ' -f 4-`
501 if [ -n "${HOST}" ]; then
502 V4=`DIG ${HOST} a`
503 V6=`DIG ${HOST} aaaa`
504 KRB=`DIG _kerberos.${HOST} txt`
505 TUN=`DIG _autotunnel._udp.${HOST} srv`
506 AT6=`DIG _autotunnel6.${HOST} aaaa`
507 else
508 V4=""
509 V6=""
510 KRB=""
511 TUN=""
512 AT6=""
513 fi
514 if [ -n "${V4}" ]; then
515 echo " v4: ${V4}" >> btmm
516 fi
517 if [ -n "${V6}" ]; then
518 echo " v6: ${V6}" >> btmm
519 fi
520 if [ -n "${KRB}" ]; then
521 echo " KRB: ${KRB}" >> btmm
522 fi
523 if [ -n "${TUN}" ]; then
524 echo " TUN: ${TUN}" >> btmm
525
526 HOST=`/bin/echo "${TUN}" | cut -d ' ' -f 4-`
527 if [ -n "${HOST}" ]; then
528 V4=`DIG ${HOST} a`
529 V6=`DIG ${HOST} aaaa`
530 fi
531 if [ -n "${V4}" ]; then
532 echo " v4: ${V4}" >> btmm
533 fi
534 if [ -n "${V6}" ]; then
535 echo " v6: ${V6}" >> btmm
536 fi
537 fi
538 if [ -n "${AT6}" ]; then
539 echo " AT6: ${AT6}" >> btmm
540 fi
541 done
542 done
543 done
544
545 #
546 # collect crash reports
547 #
548 for daemon in \
549 bootpd \
550 configd \
551 eapolclient \
552 mDNSResponder \
553 mDNSResponderHelper \
554 pppd \
555 racoon \
556 socketfilterfw \
557 SCHelper \
558 SCMonitor \
559
560 do
561 /bin/ls -1 /Library/Logs/CrashReporter/${daemon}_*.crash \
562 /Library/Logs/DiagnosticReports/${daemon}/*.crash \
563 2>/dev/null \
564 | while read log
565 do
566 b="`basename ${log}`"
567 ${PRIV} cat "${log}" > "${b}" 2>&1
568 done
569 done
570
571 #
572 # collect everything into a single archive
573 #
574 cd "${WORKDIR}/.."
575 pax -w ${GZ_OPT} -f "${ARCHIVE}" "${OUT}"
576 rm -rf "${WORKDIR}"
577
578 if [ ${UID} -eq 0 ]; then
579 if [ -n "${SUDO_UID}" -a -n "${SUDO_GID}" ]; then
580 if [ ${UID} -ne ${SUDO_UID} ]; then
581 chown ${SUDO_UID}:${SUDO_GID} "${ARCHIVE}"
582 fi
583 fi
584 fi
585
586 echo "Network data collected to \"${ARCHIVE}\""
587
588 #
589 # if requested, generate a crash report
590 #
591 if [ "${OUTDIR}" = "/Library/Logs/CrashReporter/SystemConfiguration" -a "${1}" = "CRASH" ]; then
592 kill -ABRT $$
593 fi
594