-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
63 lines (52 loc) · 1.9 KB
/
Copy pathProgram.cs
File metadata and controls
63 lines (52 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System.Net;
Console.WriteLine("UDP:");
Console.WriteLine(
"[{0,-5}] {1,-24} {2,-30} {3,-5} {4,4}",
"pid",
"module",
"local_ip",
"lport",
"active_time");
var netstat = new Netstat();
foreach (var udpConnectionInfo in netstat.GetUdpConnections().OrderBy(x => x.OwnerPid).ThenBy(x => x.Local.Address.ToString()))
{
string shortenedModuleName = Formatting.FormatModuleName(udpConnectionInfo.OwnerModuleName);
string local_ip = Formatting.FormatIpAddress(udpConnectionInfo.Local.Address);
string activeTime = Formatting.FormatActiveTime(DateTimeOffset.Now - udpConnectionInfo.Created);
Console.WriteLine(
"[{0,-5}] {1,-24} {2,-30} {3,-5} {4,4}",
udpConnectionInfo.OwnerPid,
shortenedModuleName,
local_ip,
udpConnectionInfo.Local.Port,
activeTime);
}
Console.WriteLine();
Console.WriteLine("TCP:");
Console.WriteLine(
"[{0,-5}] {1,-24} {2,-30} {3,-5} <-> {4,-30} {5,-5} {6,-12} {7,4}",
"pid",
"module",
"local_ip",
"lport",
"remote_ip",
"rport",
"tcp_state",
"active_time");
foreach (var tcpConnectionInfo in netstat.GetTcpConnections().OrderBy(x => x.OwnerPid).ThenBy(x => x.Local.Address.ToString()))
{
string shortenedModuleName = Formatting.FormatModuleName(tcpConnectionInfo.OwnerModuleName);
string local_ip = Formatting.FormatIpAddress(tcpConnectionInfo.Local.Address);
string remote_ip = Formatting.FormatIpAddress(tcpConnectionInfo.Remote.Address);
string activeTime = Formatting.FormatActiveTime(DateTimeOffset.Now - tcpConnectionInfo.Created);
Console.WriteLine(
"[{0,-5}] {1,-24} {2,-30} {3,-5} <-> {4,-30} {5,-5} {6,-12} {7,4}",
tcpConnectionInfo.OwnerPid,
shortenedModuleName,
local_ip,
tcpConnectionInfo.Local.Port,
remote_ip,
tcpConnectionInfo.Remote.Port,
tcpConnectionInfo.TcpState,
activeTime);
}