Skip to content

Instantly share code, notes, and snippets.

View igentuman's full-sized avatar
🤖
Development

Sergey igentuman

🤖
Development
View GitHub Profile
@cheynewallace
cheynewallace / NetStatPortsAndProcessNames.cs
Last active July 6, 2024 12:18
C# Get Active Ports and Associated Process Names. This code will parse the output from a "netstat -a -n -o" and retrieve a list of active listening ports, along with the associated PID. The PID is then resolved to a process name so we can see exactly which port is attached to which process.
// ===============================================
// The Method That Parses The NetStat Output
// And Returns A List Of Port Objects
// ===============================================
public static List<Port> GetNetStatPorts()
{
var Ports = new List<Port>();
try {
using (Process p = new Process()) {