4 # Copyright © 2015, 2016 Apple Inc.
8 # Collect network information.
11 PATH
=/bin
:/usr
/bin
:/sbin
:/usr
/sbin
13 # __SETUP_ROUTINES_BEGIN__
21 COLLECT_CONFIGURATION_FILES
="Y"
29 COLLECT_SENSITIVE_INFO
="Y"
36 REQUESTED_OUTDIR
="${i}"
47 if [ ${EUID} -ne 0 ]; then
60 cd "${REQUESTED_OUTDIR}"
64 # __SETUP_ROUTINES_END__
67 # __COMMAND_ROUTINES_BEGIN__
69 # note: the daemons dump to syslog so you need to wait a bit before
71 collect_state_dump_sensitive
() {
73 ${PRIV} /usr
/bin
/killall
-INFO mDNSResponder
2>/dev
/null
80 # network interface configuration
84 if [ ! -x /sbin
/ifconfig
]; then
88 /sbin
/ifconfig
-a -L -b -m -r -v -v > ifconfig.txt
2>&1
90 /sbin
/ifconfig
-a > ifconfig.txt
2>&1
96 # network route configuration and statistics
100 if [ ! -x /usr
/sbin
/netstat
]; then
104 echo "#" > netstat.txt
105 echo "# netstat -n -r -a -l" >> netstat.txt
106 echo "#" >> netstat.txt
107 /usr
/sbin
/netstat
-n -r -a -l >> netstat.txt
2>&1
109 echo "#" >> netstat.txt
110 echo "# netstat -A -a -l -n -v" >> netstat.txt
111 echo "#" >> netstat.txt
112 /usr
/sbin
/netstat
-A -a -l -n -v >> netstat.txt
2>&1
114 echo "#" >> netstat.txt
115 echo "# netstat -s" >> netstat.txt
116 echo "#" >> netstat.txt
117 /usr
/sbin
/netstat
-s >> netstat.txt
2>&1
119 echo "#" >> netstat.txt
120 echo "# netstat -rs" >> netstat.txt
121 echo "#" >> netstat.txt
122 /usr
/sbin
/netstat
-rs >> netstat.txt
2>&1
124 echo "#" >> netstat.txt
125 echo "# netstat -mmm" >> netstat.txt
126 echo "#" >> netstat.txt
127 /usr
/sbin
/netstat
-mmm >> netstat.txt
2>&1
129 echo "#" >> netstat.txt
130 echo "# netstat -i -n -d" >> netstat.txt
131 echo "#" >> netstat.txt
132 /usr
/sbin
/netstat
-i -n -d >> netstat.txt
2>&1
134 echo "#" >> netstat.txt
135 echo "# netstat -i -x R" >> netstat.txt
136 echo "#" >> netstat.txt
137 /usr
/sbin
/netstat
-i -x R
>> netstat.txt
2>&1
139 echo "#" >> netstat.txt
140 echo "# netstat -a -n -p mptcp" >> netstat.txt
141 echo "#" >> netstat.txt
142 /usr
/sbin
/netstat
-anp mptcp
>> netstat.txt
2>&1
144 echo "#" >> netstat.txt
145 echo "# netstat -s -p mptcp" >> netstat.txt
146 echo "#" >> netstat.txt
147 /usr
/sbin
/netstat
-s -p mptcp
>> netstat.txt
2>&1
149 echo "#" >> netstat.txt
150 echo "# netstat -g -n -s" >> netstat.txt
151 echo "#" >> netstat.txt
152 /usr
/sbin
/netstat
-g -n -s >> netstat.txt
2>&1
154 if [ -x /sbin
/ifconfig
]; then
157 IF_INFO
=`/sbin/ifconfig -v ${if}`
158 `echo $IF_INFO | grep -q TXSTART`
159 if [ $?
-eq 0 ]; then
160 echo "#" >> netstat.txt
161 echo "# netstat -qq -I ${if}" >> netstat.txt
162 echo "#" >> netstat.txt
163 /usr
/sbin
/netstat
-qq -I ${if} >> netstat.txt
2>&1
165 `echo $IF_INFO | grep -q RXPOLL`
166 if [ $?
-eq 0 ]; then
167 echo "#" >> netstat.txt
168 echo "# netstat -Q -I ${if}" >> netstat.txt
169 echo "#" >> netstat.txt
170 /usr
/sbin
/netstat
-Q -I ${if} >> netstat.txt
2>&1
182 if [ ! -x /usr
/sbin
/ndp
]; then
186 echo "#" > ndp
-info.txt
187 echo "# ndp -n -a" >> ndp
-info.txt
188 echo "#" >> ndp
-info.txt
189 /usr
/sbin
/ndp
-n -a >> ndp
-info.txt
2>&1
191 echo "#" >> ndp
-info.txt
192 echo "# ndp -n -p" >> ndp
-info.txt
193 echo "#" >> ndp
-info.txt
194 /usr
/sbin
/ndp
-n -p >> ndp
-info.txt
2>&1
196 echo "#" >> ndp
-info.txt
197 echo "# ndp -n -r" >> ndp
-info.txt
198 echo "#" >> ndp
-info.txt
199 /usr
/sbin
/ndp
-n -r >> ndp
-info.txt
2>&1
201 if [ -x /sbin
/ifconfig
]; then
204 echo "#" >> ndp
-info.txt
205 echo "# ndp -i ${if}" >> ndp
-info.txt
206 echo "#" >> ndp
-info.txt
207 /usr
/sbin
/ndp
-i ${if} >> ndp
-info.txt
2>&1
218 if [ ! -x /usr
/sbin
/arp
]; then
222 echo "#" > arp
-info.txt
223 echo "# arp -n -a" >> arp
-info.txt
224 echo "#" >> arp
-info.txt
225 /usr
/sbin
/arp
-n -a >> arp
-info.txt
2>&1
234 if [ ! -x /usr
/sbin
/ipconfig
]; then
244 echo "#" >> ipconfig
-info.txt
245 echo "# INTERFACE ${if}" >> ipconfig
-info.txt
246 echo "#" >> ipconfig
-info.txt
248 echo "DHCPv4 information:" >> ipconfig
-info.txt
250 IPCONFIG_INFO
=`/usr/sbin/ipconfig getpacket ${if}`
251 if [ "${IPCONFIG_INFO}" != "" ]; then
252 echo "${IPCONFIG_INFO}" >> ipconfig
-info.txt
254 echo "not available" >> ipconfig
-info.txt
257 echo"" >> ipconfig
-info.txt
259 echo "DHCPv6 information:" >> ipconfig
-info.txt
261 IPCONFIG_INFO
=`/usr/sbin/ipconfig getv6packet ${if}`
262 if [ "${IPCONFIG_INFO}" != "" ]; then
263 echo "${IPCONFIG_INFO}" >> ipconfig
-info.txt
265 echo "not available" >> ipconfig
-info.txt
268 echo"" >> ipconfig
-info.txt
276 # IPsec configuration
280 if [ ! -x /usr
/sbin
/setkey
-o ! -x /usr
/bin
/perl
]; then
285 echo "# setkey -D" >> ipsec.txt
286 echo "#" >> ipsec.txt
287 ${PRIV} /usr
/sbin
/setkey
-D \
288 | /usr
/bin
/perl
-l -n -e '
289 if (/^(\s+[AE]:\s+\S+\s+)"?(.*)"?\s*$/) {
290 printf "%s[redacted]%s\n", $1, $3;
297 echo "#" >> ipsec.txt
298 echo "# setkey -Pp -D" >> ipsec.txt
299 echo "#" >> ipsec.txt
300 ${PRIV} /usr
/sbin
/setkey
-Pp -D >> ipsec.txt
302 for CF
in /var
/run
/racoon
/*.conf
304 if [ ! -r "${CF}" ]; then
309 echo "#" >> ipsec.txt
310 echo "# ${CF}" >> ipsec.txt
311 echo "#" >> ipsec.txt
313 | /usr
/bin
/perl
-l -n -e '
314 if (/^(\s+shared_secret\s+use\s+)"?([^\s;"]+)"?(.*)/) {
315 printf "%s[redacted]%s\n", $1, $3;
325 # Network preferences
327 collect_configuration_files
() {
330 /Library
/Preferences
/com.apple.networkextension.plist \
331 /Library
/Preferences
/com.apple.networkextension.control.plist \
332 /Library
/Preferences
/com.apple.networkextension.necp.plist \
333 /Library
/Preferences
/SystemConfiguration
/com.apple.nat.plist \
334 /Library
/Preferences
/SystemConfiguration
/com.apple.RemoteAccessServers.plist \
335 /Library
/Preferences
/SystemConfiguration
/com.apple.smb.server.plist \
336 /Library
/Preferences
/com.apple.mDNSResponder.plist \
337 /Library
/Preferences
/SystemConfiguration
/NetworkInterfaces.plist \
338 /Library
/Preferences
/SystemConfiguration
/preferences.plist \
341 if [ -e "${f}" ]; then
343 cat "${f}" > "${b}" 2>&1
347 if [ -e /etc
/resolv.conf
]; then
348 cat /etc
/resolv.conf
> etc
-resolv-conf.txt
2>&1
350 if [ -e /var
/run
/resolv.conf
]; then
351 cat /var
/run
/resolv.conf
> var
-run-resolv-conf.txt
2>&1
353 if [ -e /etc
/resolver
]; then
354 tar -c -H /etc
/resolver
> etc
-resolver.
tar 2>/dev
/null
361 collect_vpn_logs
() {
365 /var
/log
/racoon.log \
368 if [ -e "${f}" ]; then
370 ${PRIV} cat "${f}" > "${b}".txt
2>&1
380 if [ ! -x /usr
/local
/bin
/neutil
]; then
385 echo "# neutil policy dump" >> necp.txt
387 /usr
/local
/bin
/neutil policy dump
>> necp.txt
2>&1
389 echo "#" > network
-agents.txt
390 echo "# neutil agent dump" >> network
-agents.txt
391 echo "#" >> network
-agents.txt
392 /usr
/local
/bin
/neutil agent dump
>> network
-agents.txt
2>&1
399 run_network_test
() {
401 if [ ! -x /usr
/local
/bin
/network_test
]; then
405 /usr
/local
/bin
/network_test path_watcher
> nw_path.txt
2>&1
410 # Network, DNS, Proxy, Reachability, Cache information
414 if [ ! -x /usr
/sbin
/scutil
]; then
418 echo "#" > network
-information.txt
419 echo "# scutil -d -v --nwi" >> network
-information.txt
420 echo "#" >> network
-information.txt
421 /usr
/sbin
/scutil
-d -v --nwi >> network
-information.txt
2>&1
424 echo "" >> network
-information.txt
425 echo "#" >> network
-information.txt
426 echo "# scutil --nwi ${if}" >> network
-information.txt
427 echo "#" >> network
-information.txt
428 scutil
--nwi ${if} >> network
-information.txt
2>&1
431 echo "#" > dns
-configuration.txt
432 echo "# scutil -d -v --dns" >> dns
-configuration.txt
433 echo "#" >> dns
-configuration.txt
434 /usr
/sbin
/scutil
-d -v --dns >> dns
-configuration.txt
2>&1
436 echo "#" > proxy
-configuration.txt
437 echo "# scutil -d -v --proxy" >> proxy
-configuration.txt
438 echo "#" >> proxy
-configuration.txt
439 /usr
/sbin
/scutil
-d -v --proxy >> proxy
-configuration.txt
2>&1
441 echo "#" > reachability
-info.txt
442 echo '# scutil -d -v -r www.apple.com' >> reachability
-info.txt
443 echo "#" >> reachability
-info.txt
444 /usr
/sbin
/scutil
-d -v -r www.apple.com
>> reachability
-info.txt
2>&1
446 echo "#" >> reachability
-info.txt
447 echo '# scutil -d -v -r 0.0.0.0' >> reachability
-info.txt
448 echo "#" >> reachability
-info.txt
449 /usr
/sbin
/scutil
-d -v -r 0.0.0.0 >> reachability
-info.txt
2>&1
451 echo "#" >> reachability
-info.txt
452 echo '# scutil -d -v -r 169.254.0.0' >> reachability
-info.txt
453 echo "#" >> reachability
-info.txt
454 /usr
/sbin
/scutil
-d -v -r 169.254.0.0 >> reachability
-info.txt
2>&1
456 echo "#" > nc
-info.txt
457 echo '# scutil --nc list' >> nc
-info.txt
458 echo "#" >> nc
-info.txt
459 /usr
/sbin
/scutil
--nc list
>> nc
-info.txt
2>&1
461 ${PRIV} /usr
/sbin
/scutil
-p --snapshot
462 if [ -f /var
/tmp
/configd
-store.plist
]; then
463 cat /var
/tmp
/configd
-store.plist
> configd
-store.plist
2>&1
465 if [ -f /var
/tmp
/configd
-pattern.plist
]; then
466 cat /var
/tmp
/configd
-pattern.plist
> configd
-pattern.plist
2>&1
468 if [ -f /var
/tmp
/configd
-session.plist
]; then
469 cat /var
/tmp
/configd
-session.plist
> configd
-session.plist
2>&1
471 if [ -f /var
/tmp
/configd
-state ]; then
472 cat /var
/tmp
/configd
-state > configd
-state 2>&1
482 if [ ! -x /sbin
/route
]; then
486 echo "#" > route
-info.txt
487 echo '# route -n -v get www.apple.com' >> route
-info.txt
488 echo "#" >> route
-info.txt
489 /sbin
/route
-n -v get www.apple.com
>> route
-info.txt
2>&1
491 echo "#" >> route
-info.txt
492 echo '# route -n -v get 0.0.0.0' >> route
-info.txt
493 echo "#" >> route
-info.txt
494 /sbin
/route
-n -v get
0.0.0.0 >> route
-info.txt
2>&1
503 if [ ! -x /usr
/bin
/dig -o ! -f /etc
/resolv.conf
]; then
507 echo "#" > dig-info.txt
508 echo '# dig -t any -c any www.apple.com' >> dig-info.txt
509 echo "#" >> dig-info.txt
510 /usr
/bin
/dig +time=2 -t any
-c any www.apple.com
>> dig-info.txt
2>/dev
/null
519 if [ ! -x /bin
/hostname
]; then
523 /bin
/hostname
> hostname.txt
2>&1
532 if [ ! -x /usr
/sbin
/lsof
]; then
536 ${PRIV} /usr
/sbin
/lsof
-i -n -O -P -T q
> lsof.txt
2>&1 &
538 # start a watchdog for lsof
541 while [ $WAIT_TIME -gt 0 ]
543 ${PRIV} kill -0 ${LSOF_PID} 2>/dev
/null
544 if [ $?
-eq 0 ]; then
545 # lsof is [still] gathering data...
547 WAIT_TIME
=$((WAIT_TIME - 1))
551 # lsof completed gathering data
555 if [ $WAIT_TIME -eq 0 ]; then
557 ${PRIV} kill ${LSOF_PID} 2>/dev
/null
563 collect_ndf_info
() {
567 collect_sensitive_info
() {
568 collect_state_dump_sensitive
577 if [ "${COLLECT_NDF_INFO}" == "Y" ]; then
581 if [ "${COLLECT_SENSITIVE_INFO}" == "Y" ]; then
582 collect_sensitive_info
595 if [ "${COLLECT_CONFIGURATION_FILES}" == "Y" ]; then
596 collect_configuration_files
600 # __COMMAND_ROUTINES_END__
602 # __HELPER_ROUTINES_BEGIN__
606 echo "Usage: get-network-info [-c] [-n] [-s] <info-directory>"
607 echo " -c collects system configuration files"
608 echo " -n collects NDF information (lsof)"
609 echo " -s collects sensitive information (ARP/NDP/mDNS cache)"
610 echo " <info-directory> path to directory where all the information will be collected"
616 if [ ! -d ${REQUESTED_OUTDIR} ] ||
617 [ "${REQUESTED_OUTDIR}" = "" ]; then
622 if [ ! -w ${REQUESTED_OUTDIR} ]; then
623 echo "${REQUESTED_OUTDIR} is write-protected"
629 # Collect most used command output to be used later
633 if [ ! -x /sbin
/ifconfig
]; then
637 IF_LIST
=`/sbin/ifconfig -l`
643 COLLECT_SENSITIVE_INFO
=""
644 COLLECT_CONFIGURATION_FILES
=""
647 # __HELPER_ROUTINES_END__