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