collect tcpdump programatically
Catalin-Emil Fetoiu committed
Oct 19, 2023 at 14:16 UTC
28e5bbe48796f2fdac5b840f4e5ce56aefb0641b
2 files changed
+32
-4
CONTRIBUTING.md
+15
-4
@@ -119,12 +119,23 @@ Availability Capabilities CapabilityDescriptions
119
120
#### Collect WSL logs for networking issues
121
122
-To collect WSL networking logs, download and execute [collect-wsl-logs.ps1](https://github.com/Microsoft/WSL/blob/master/diagnostics/collect-networking-logs.ps1) in an administrative powershell prompt:
122
+Install tcpdump in your WSL distribution using the following commands.
123
+Note: This will not work if WSL has Internet connectivity issues.
124
125
```
125
-Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-networking-logs.ps1" -OutFile collect-networking-logs.ps1
126
-Set-ExecutionPolicy Bypass -Scope Process -Force
127
-.\collect-networking-logs.ps1
126
+# sudo apt-get update
127
+# sudo apt-get -y install tcpdump
128
+```
129
+
130
+To collect WSL networking logs, do the following steps in an administrative powershell prompt:
131
+
132
+```
133
+$ Invoke-WebRequest 'https://github.com/microsoft/WSL/archive/refs/heads/master.zip' -OutFile .\wsl.zip
134
+$ Expand-Archive .\wsl.zip .\
135
+$ Remove-Item .\wsl.zip
136
+$ cd .\WSL-master\diagnostics
137
+$ Set-ExecutionPolicy Bypass -Scope Process -Force
138
+$ .\collect-networking-logs.ps1
139
```
140
The script will output the path of the log file once done.
141
diagnostics/collect-networking-logs.ps1
+17
@@ -56,6 +56,14 @@ pktmon start -c --flags 0x1A --file-name "$folder/pktmon.etl" | out-null
56
# Start WFP capture
57
netsh wfp capture start file="$folder/wfpdiag.cab"
58
59
+# Start tcpdump. Using a try/catch as tcpdump might not be installed
60
+$tcpdumpProcess = $null
61
+try
62
+{
63
+ $tcpdumpProcess = Start-Process wsl.exe -ArgumentList "-u root /bin/bash -c 'tcpdump -n -i any > $folder/tcpdump.log'" -PassThru
64
+}
65
+catch {}
66
+
67
try
68
{
69
Write-Host -NoNewLine -ForegroundColor Green "Log collection is running. Please reproduce the problem and press any key to save the logs."
@@ -99,6 +107,15 @@ try
107
}
108
finally
109
{
110
+ try
111
+ {
112
+ if ($tcpdumpProcess -ne $null)
113
+ {
114
+ Stop-Process -InputObject $tcpdumpProcess
115
+ }
116
+ }
117
+ catch {}
118
+
119
netsh wfp capture stop
120
pktmon stop | out-null
121
wpr.exe -stop $folder/logs.etl 2>&1 >> $wprOutputLog