Skip to content

Instantly share code, notes, and snippets.

@jrmillr1
Created September 22, 2020 03:01
Show Gist options
  • Save jrmillr1/bfd8e4ba06ab6e2959e36efe2dcff834 to your computer and use it in GitHub Desktop.
Save jrmillr1/bfd8e4ba06ab6e2959e36efe2dcff834 to your computer and use it in GitHub Desktop.
Simple ditty to do a packet capture on Windows 10
<#
Author: JR Miller
Date: 02-20-2020
Version: 1.0
Use: Simple PS to capture some packets.
#>
Set-StrictMode -Version 2.0
# Set-PSDebug -Trace 2
function Get-NetworkScenario
{
$netScenario = Read-Host "Choose a Scenario; Enter L for Wired LAN or W for Wireless"
Switch ($netScenario)
{
L {$netScenario="Wired LAN"}
W {$netScenario="Wireless LAN"}
}
return $netScenario
}
#Verify we have Admin rights
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$isAdmin = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if($isAdmin -match "False"){
Write-Output "This Powershell session does not have Admin rights."
exit
}
#Create a timestamp, I like epoch time
$myEpoch = (New-TimeSpan -Start (Get-Date "01/01/1970") -End (Get-Date)).TotalSeconds
#Create a file and directory for our captures
New-Item -Path "c:\" -Name "capfiles" -ItemType "directory" -Force
$myCapFile = "c:\capfiles\capFile.$myEpoch.etl"
#Get Wire or wireless scenario
Write-Host ""
$myScenario = Get-NetworkScenario
Write-Host ""
#Startit
Read-Host "Press ENTER to start capture. This might take a minute"
if($myScenario -match "Wireless LAN"){
netsh trace start capture=yes wifi.type=data Ethernet.type=IPV4 report=disabled tracefile=$myCapFile
}
elseif ($myScenario -match "Wired LAN") {
netsh trace start capture=yes report=disabled tracefile=$myCapFile
}
else {
Write-Host "No selection exists, exiting."
exit
}
#Stoppit
Read-Host "Press Enter to stop capture. This might take a while, do not kill the session."
netsh trace stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment