Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <# : Batch Script Section
- @rem # The previous line does nothing in Batch, but begins a multiline comment block in PowerShell. This allows a single script to be executed by both interpreters.
- @echo off
- Title Scan TCP connections On Windows by Hackoo 2023 & Mode 80,10
- setlocal
- cd "%~dp0"
- Color 1B & echo( & Echo(
- Echo( Please Wait ... Scanning TCP connections On Windows ...
- Powershell -executionpolicy bypass -Command "Invoke-Expression $([System.IO.File]::ReadAllText('%~f0'))"
- pause
- EndLocal
- goto:eof
- #>
- # Powershell Script Section begin here...
- # Here we execute our powershell commands...
- Clear-Host
- Write-Host Please Wait a While... -Fore Cyan
- # Get the list separator value from the registry
- $ListSeparator = (Get-ItemProperty "HKCU:\Control Panel\International" -Name sList).sList
- # Get the total number of TCP connections to be processed
- $TotalConnections = (Get-NetTCPConnection).Count
- # Initialize the progress bar
- $Progress = 0
- Write-Progress -Activity "Processing TCP connections" -Status "Starting..." -PercentComplete 0
- $TCP_Var = Get-NetTCPConnection | ForEach-Object {
- # Increment the progress bar
- $Progress++
- Write-Progress -Activity "Processing TCP connections" -Status "Progress: $($Progress)/$($TotalConnections)" -PercentComplete (($Progress / $TotalConnections) * 100)
- $process = Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue
- $_ | Add-Member -MemberType NoteProperty -Name "RemoteHostName" -Value (Resolve-DnsName $_.RemoteAddress -ErrorAction SilentlyContinue).NameHost -PassThru |
- Add-Member -MemberType NoteProperty -Name "ProcessName" -Value $process.ProcessName -PassThru |
- Add-Member -MemberType NoteProperty -Name "ProcessPath" -Value $process.Path -PassThru
- } |
- Select-Object OwningProcess, ProcessName, ProcessPath, State, LocalAddress, LocalPort, RemoteHostName, RemoteAddress, RemotePort
- # Hide the progress bar
- Write-Progress -Activity "Processing TCP connections" -Completed
- Clear-Host
- $TCP_Var | Out-GridView -Title "NET TCP CONNECTIONS" -PassThru
- # Save the results to a log file on the desktop of the user in JSON format
- $LogFilePath = "$([Environment]::GetFolderPath('Desktop'))\TCP_Connections_Log.json"
- $TCP_Var | ConvertTo-Json | Out-File -FilePath $LogFilePath
- Write-Host "Results saved to $LogFilePath" -Fore Green
- # Save the results to a log file on the desktop of the user in XML format
- $LogFilePath = "$([Environment]::GetFolderPath('Desktop'))\TCP_Connections_Log.xml"
- $TCP_Var | Export-Clixml -Path $LogFilePath
- Write-Host "Results saved to $LogFilePath" -Fore Green
- # Save the results to a log file on the desktop of the user
- $LogFilePath = "$([Environment]::GetFolderPath('Desktop'))\TCP_Connections_Log.csv"
- $TCP_Var | Export-Csv -Path $LogFilePath -Delimiter $ListSeparator -NoTypeInformation
- Write-Host "Results saved to $LogFilePath" -Fore Green
Add Comment
Please, Sign In to add comment