Repository navigation
Expand file tree
/
Copy pathListener.cs
More file actions
57 lines (42 loc) · 1.52 KB
/
Copy pathListener.cs
File metadata and controls
57 lines (42 loc) · 1.52 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
using System.Collections.Generic;
using System.Net.NetworkInformation;
using System.Threading.Tasks;
namespace NETworkManager.Models.Network;
public class Listener
{
#region Methods
public static Task<List<ListenerInfo>> GetAllActiveListenersAsync()
{
return Task.Run(() => GetAllActiveListeners());
}
public static List<ListenerInfo> GetAllActiveListeners()
{
var list = new List<ListenerInfo>();
list.AddRange(GetActiveTcpListeners());
list.AddRange(GetActiveUdpListeners());
return list;
}
public static Task<List<ListenerInfo>> GetActiveTcpListenersAsync()
{
return Task.Run(() => GetActiveTcpListeners());
}
public static List<ListenerInfo> GetActiveTcpListeners()
{
var list = new List<ListenerInfo>();
foreach (var ipEndPoint in IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners())
list.Add(new ListenerInfo(TransportProtocol.Tcp, ipEndPoint.Address, ipEndPoint.Port));
return list;
}
public static Task<List<ListenerInfo>> GetActiveUdpListenersAsync()
{
return Task.Run(() => GetActiveUdpListeners());
}
public static List<ListenerInfo> GetActiveUdpListeners()
{
var list = new List<ListenerInfo>();
foreach (var ipEndPoint in IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners())
list.Add(new ListenerInfo(TransportProtocol.Udp, ipEndPoint.Address, ipEndPoint.Port));
return list;
}
#endregion
}