Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

NetStat – Get Network Statistics

Posted on May 16, 2016June 16, 2020 By David Kittell
sudo lsof -i # Get all network traffic information
sudo lsof -i |grep *:http # Get all network traffic information using port 80 HTTP
netstat -tulpn # Get all network traffic information
netstat -tulpn | grep :80 # Get all network traffic information using port 80 HTTP
netstat -o # Get all network traffic information
Get-NetTCPConnection | `
	Where-Object {  `
		$_.State -eq "Listen" `
	} | `
	Sort-Object State, LocalPort | `
	Format-Table -AutoSize `
		LocalAddress, `
		LocalPort, `
		RemoteAddress, `
		RemotePort, `
		State, `
		@{l = "Process/Application"; e = { `
				$(Get-Process -PID $_.OwningProcess | Select-Object ID, ProcessName).ProcessName `
			} `
		}
function Get-NetStat 
    {
        $proc = @{};
        Get-Process | ForEach-Object { $proc.Add($_.Id, $_) };
        netstat -aon | Select-String "\s*([^\s]+)\s+([^\s]+):([^\s]+)\s+([^\s]+):([^\s]+)\s+([^\s]+)?\s+([^\s]+)" | ForEach-Object {
            $g = $_.Matches[0].Groups;
            New-Object PSObject | 
                Add-Member @{ Protocol =           $g[1].Value  } -PassThru |
                Add-Member @{ LocalAddress =       $g[2].Value  } -PassThru |
                Add-Member @{ LocalPort =     [int]$g[3].Value  } -PassThru |
                Add-Member @{ RemoteAddress =      $g[4].Value  } -PassThru |
                Add-Member @{ RemotePort =         $g[5].Value  } -PassThru |
                Add-Member @{ State =              $g[6].Value  } -PassThru |
                Add-Member @{ PID =           [int]$g[7].Value  } -PassThru |
                Add-Member @{ Process = $proc[[int]$g[7].Value] } -PassThru;
                #} | Format-Table Protocol,LocalAddress,LocalPort,RemoteAddress,RemotePort,State -GroupBy @{Name='Process';Expression={$p=$_.Process;@{$True=$p.ProcessName; $False=$p.MainModule.FileName}[$p.MainModule -eq $Null] + ' PID: ' + $p.Id}} -AutoSize
        } | Sort-Object PID | format-table
    }
Get-NetStat
Originally Posted on May 16, 2016
Last Updated on June 16, 2020
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

CentOS Code Fedora Mac OSX PowerShell Red Hat Ubuntu UNIX UNIX Shell Scripts netstatNetwork InformationNetwork StatisticsPortsProcesses

Post navigation

Previous post
Next post

Related Posts

Ektron – Remove Content/Folder Permissions

Posted on August 20, 2014October 26, 2015

Use EXTREME caution on this query. I recommend you do a backup of your database before you run this script as this will remove all permissions that someone has setup on Ektron. TRUNCATE TABLE [permissions_tbl]; UPDATE [content] SET [inherit_permissions] = 0 ,[inherit_permissions_from] = 0 ,[private] = 0; Originally Posted on…

Read More

Format Date Function

Posted on July 31, 2013October 26, 2015

IF OBJECT_ID(N’dbo.fnFormatDate’) IS NOT NULL DROP FUNCTION dbo.fnFormatDate GO CREATE FUNCTION dbo.fnFormatDate ( @MyDate DATETIME ,@Format NVARCHAR(50) ,@LANGUAGE INT = NULL ) RETURNS NVARCHAR(255) AS BEGIN /* SELECT dbo.fnFormatDate(GetDate(), ‘MMMM DDDD DD, YYYY HH:NN:SS AMPM’, NULL) –October Friday 03, 2013 00:13:28 PM SELECT dbo.fnFormatDate(GetDate(), ‘MMMM DDDD DD, YYYY HH:NN:SS AMPM’,…

Read More

Battery Life

Posted on May 3, 2013February 8, 2016

By its self this code is rather simple and meaningless but useful when adding to scheduled tasks or applications that take a long time to run and have the potential of running on a laptop. Before using the code below in Design View you’ll need these: 1 Progress Bar 2…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes
 

Loading Comments...
 

You must be logged in to post a comment.