Minor updates to collect-networking-logs.ps1
* enable log collection to work offline (using local copies of networking.sh and wsl_networking.wprp, if existing) * enable alternative mechanism to end log collection, in addition to keypress - termination of process tcpdump.
Slavy Mihov committed
Mar 4, 2024 at 10:36 UTC
5c5e6dcacf6820b26a8d4316c1af06f1cd205cd9
1 file changed
+30
-6
diagnostics/collect-networking-logs.ps1
+30
-6
@@ -11,9 +11,26 @@ mkdir -p $folder
11
$logProfile = "$folder/wsl_networking.wprp"
12
$networkingBashScript = "$folder/networking.sh"
13
14
-# Download supporting files
15
-Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/wsl_networking.wprp" -OutFile $logProfile
16
-Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/networking.sh" -OutFile $networkingBashScript
14
+# Copy/Download supporting files
15
+if (Test-Path "$PSScriptRoot/wsl_networking.wprp")
16
+{
17
+ Copy-Item "$PSScriptRoot/wsl_networking.wprp" $logProfile
18
+}
19
+else
20
+{
21
+ Write-Host -ForegroundColor Yellow "wsl_networking.wprp not found in the current directory. Downloading it from GitHub."
22
+ Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/wsl_networking.wprp" -OutFile $logProfile
23
+}
24
+
25
+if (Test-Path "$PSScriptRoot/networking.sh")
26
+{
27
+ Copy-Item "$PSScriptRoot/networking.sh" $networkingBashScript
28
+}
29
+else
30
+{
31
+ Write-Host -ForegroundColor Yellow "networking.sh not found in the current directory. Downloading it from GitHub."
32
+ Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/networking.sh" -OutFile $networkingBashScript
33
+}
34
35
# Retrieve WSL version and wslconfig file
36
get-appxpackage MicrosoftCorporationII.WindowsSubsystemforLinux > $folder/appxpackage.txt
@@ -105,9 +122,16 @@ try
122
183 # Application 2
123
124
$Key = $null
108
- while ($Key -Eq $null -Or $Key.VirtualKeyCode -Eq $null -Or $KeysToIgnore -Contains $Key.VirtualKeyCode)
125
+ while (($Key -Eq $null -Or $Key.VirtualKeyCode -Eq $null -Or $KeysToIgnore -Contains $Key.VirtualKeyCode) -and ($null -eq $tcpdumpProcess -or $tcpdumpProcess.HasExited -eq $false))
126
{
110
- $Key = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
127
+ if ([console]::KeyAvailable)
128
+ {
129
+ $Key = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
130
+ }
131
+ else
132
+ {
133
+ Start-Sleep -Seconds 1
134
+ }
135
}
136
137
Write-Host "`nSaving logs..."
@@ -238,4 +262,4 @@ $logArchive = "$(Resolve-Path $folder).zip"
262
Compress-Archive -Path $folder -DestinationPath $logArchive
263
Remove-Item $folder -Recurse
264
241
-Write-Host -ForegroundColor Green "Logs saved in: $logArchive. Please attach that file to the GitHub issue."
\ No newline at end of file
265
+Write-Host -ForegroundColor Green "Logs saved in: $logArchive. Please attach that file to the GitHub issue."