Skip to content

Commit 93e2651

Browse files
authored
Application "Connections" added (#101)
* GetActiveTCPConnections added * GetActiveTcpListeners added * GetActiveUdpListeners added * AutoRefreshTime added * AutoRefresh added
1 parent 5d2a336 commit 93e2651

24 files changed

Lines changed: 1497 additions & 19 deletions

Source/NETworkManager/ApplicationViewManager.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public static List<ApplicationViewInfo> List
2626
new ApplicationViewInfo(Name.HTTPHeaders, new PackIconMaterial() { Kind = PackIconMaterialKind.Web }),
2727
new ApplicationViewInfo(Name.SubnetCalculator, new PackIconModern() { Kind = PackIconModernKind.Calculator }),
2828
new ApplicationViewInfo(Name.Lookup, new PackIconMaterial() { Kind = PackIconMaterialKind.Magnify }),
29+
new ApplicationViewInfo(Name.Connections, new PackIconModern() {Kind = PackIconModernKind.Connect }),
30+
new ApplicationViewInfo(Name.Listeners, new PackIconMaterial() {Kind = PackIconMaterialKind.Wan}),
2931
new ApplicationViewInfo(Name.ARPTable, new PackIconMaterial() { Kind = PackIconMaterialKind.TableOfContents })
3032
};
3133
}
@@ -52,6 +54,8 @@ public enum Name
5254
HTTPHeaders,
5355
SubnetCalculator,
5456
Lookup,
57+
Connections,
58+
Listeners,
5559
ARPTable
5660
}
5761
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using NETworkManager.Models.Settings;
2+
using NETworkManager.Utilities;
3+
using System;
4+
using System.Globalization;
5+
using System.Windows.Data;
6+
using static NETworkManager.Utilities.AutoRefreshTime;
7+
8+
namespace NETworkManager.Converters
9+
{
10+
public sealed class AutoRefreshTimeToStringConverter : IValueConverter
11+
{
12+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
13+
{
14+
TimeUnit timeUnit = (TimeUnit)value;
15+
16+
string timeUnitTranslated = LocalizationManager.GetStringByKey("String_TimeUnit_" + timeUnit.ToString());
17+
18+
if (string.IsNullOrEmpty(timeUnitTranslated))
19+
return timeUnit.ToString();
20+
21+
return timeUnitTranslated;
22+
}
23+
24+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
25+
{
26+
throw new NotImplementedException();
27+
}
28+
}
29+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using NETworkManager.Models.Settings;
2+
using System;
3+
using System.Globalization;
4+
using System.Net.NetworkInformation;
5+
using System.Windows.Data;
6+
7+
namespace NETworkManager.Converters
8+
{
9+
public sealed class TcpStateToStringConverter : IValueConverter
10+
{
11+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
12+
{
13+
TcpState tcpState = (TcpState)value;
14+
15+
string status = LocalizationManager.GetStringByKey("String_TcpState_" + tcpState.ToString());
16+
17+
if (string.IsNullOrEmpty(status))
18+
return tcpState.ToString();
19+
20+
return status;
21+
}
22+
23+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
24+
{
25+
throw new NotImplementedException();
26+
}
27+
}
28+
}

Source/NETworkManager/MainWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
<MenuItem.Icon>
6767
<Rectangle Width="16" Height="16" Fill="{DynamicResource BlackColorBrush}">
6868
<Rectangle.OpacityMask>
69-
<VisualBrush Stretch="Uniform" Visual="{IconPacks:Modern Kind=Settings}" />
69+
<VisualBrush Stretch="Uniform" Visual="{IconPacks:MaterialLight Kind=Cog}" />
7070
</Rectangle.OpacityMask>
7171
</Rectangle>
7272
</MenuItem.Icon>
@@ -508,7 +508,7 @@
508508
</Grid.ColumnDefinitions>
509509
<Rectangle Grid.Column="0" Width="24" Height="24">
510510
<Rectangle.OpacityMask>
511-
<VisualBrush Stretch="Uniform" Visual="{IconPacks:Modern Kind=Settings}" />
511+
<VisualBrush Stretch="Uniform" Visual="{IconPacks:MaterialLight Kind=Cog}" />
512512
</Rectangle.OpacityMask>
513513
<Rectangle.Style>
514514
<Style TargetType="{x:Type Rectangle}">

Source/NETworkManager/MainWindow.xaml.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,13 @@ private async void MetroWindowMain_Closing(object sender, CancelEventArgs e)
421421
SubnetCalculatorHostView subnetCalculatorHostView;
422422
HTTPHeadersHostView httpHeadersHostView;
423423
LookupHostView lookupHostView;
424+
ConnectionsView connectionsView;
425+
ListenersView listenersView;
424426
ARPTableView arpTableView;
425427

426428
private ApplicationViewManager.Name? currentApplicationViewName = null;
427429

428-
private void ChangeApplicationView(ApplicationViewManager.Name name, EventSystemRedirectApplicationArgs args = null)
430+
private void ChangeApplicationView(ApplicationViewManager.Name name)
429431
{
430432
if (currentApplicationViewName == name)
431433
return;
@@ -448,10 +450,6 @@ private void ChangeApplicationView(ApplicationViewManager.Name name, EventSystem
448450
if (portScannerHostView == null)
449451
portScannerHostView = new PortScannerHostView();
450452

451-
// Create a new tab
452-
if (args != null)
453-
portScannerHostView.AddTab(args.Data);
454-
455453
contentControlApplication.Content = portScannerHostView;
456454
break;
457455
case ApplicationViewManager.Name.Ping:
@@ -515,6 +513,18 @@ private void ChangeApplicationView(ApplicationViewManager.Name name, EventSystem
515513

516514
contentControlApplication.Content = lookupHostView;
517515
break;
516+
case ApplicationViewManager.Name.Connections:
517+
if (connectionsView == null)
518+
connectionsView = new ConnectionsView();
519+
520+
contentControlApplication.Content = connectionsView;
521+
break;
522+
case ApplicationViewManager.Name.Listeners:
523+
if (listenersView == null)
524+
listenersView = new ListenersView();
525+
526+
contentControlApplication.Content = listenersView;
527+
break;
518528
case ApplicationViewManager.Name.ARPTable:
519529
if (arpTableView == null)
520530
arpTableView = new ARPTableView();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Collections.Generic;
2+
using System.Net.NetworkInformation;
3+
using System.Threading.Tasks;
4+
5+
namespace NETworkManager.Models.Network
6+
{
7+
public class Connection
8+
{
9+
#region Methods
10+
public static Task<List<ConnectionInfo>> GetActiveTcpConnectionsAsync()
11+
{
12+
return Task.Run(() => GetActiveTcpConnections());
13+
}
14+
15+
public static List<ConnectionInfo> GetActiveTcpConnections()
16+
{
17+
List<ConnectionInfo> list = new List<ConnectionInfo>();
18+
19+
foreach (TcpConnectionInformation tcpInfo in IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections())
20+
list.Add(new ConnectionInfo(Protocol.TCP, tcpInfo.LocalEndPoint.Address, tcpInfo.LocalEndPoint.Port, tcpInfo.RemoteEndPoint.Address, tcpInfo.RemoteEndPoint.Port, tcpInfo.State));
21+
22+
return list;
23+
}
24+
#endregion
25+
26+
#region Enum
27+
public enum Protocol
28+
{
29+
TCP
30+
}
31+
32+
#endregion
33+
}
34+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using NETworkManager.Utilities;
2+
using System.Net;
3+
using System.Net.NetworkInformation;
4+
using static NETworkManager.Models.Network.Connection;
5+
6+
namespace NETworkManager.Models.Network
7+
{
8+
public class ConnectionInfo
9+
{
10+
public Protocol Protocol { get; set; }
11+
public IPAddress LocalIPAddress { get; set; }
12+
public int LocalPort { get; set; }
13+
public IPAddress RemoteIPAddress { get; set; }
14+
public int RemotePort { get; set; }
15+
public TcpState State { get; set; }
16+
17+
public int LocalIPAddressInt32
18+
{
19+
get { return LocalIPAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork ? IPv4AddressHelper.ConvertToInt32(LocalIPAddress) : 0; }
20+
}
21+
22+
public int RemoteIPAddressInt32
23+
{
24+
get { return LocalIPAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork ? IPv4AddressHelper.ConvertToInt32(RemoteIPAddress) : 0; }
25+
}
26+
27+
public ConnectionInfo()
28+
{
29+
30+
}
31+
32+
public ConnectionInfo(Protocol protocol, IPAddress localIPAddress, int localPort, IPAddress remoteIPAddress, int remotePort, TcpState state)
33+
{
34+
Protocol = protocol;
35+
LocalIPAddress = localIPAddress;
36+
LocalPort = localPort;
37+
RemoteIPAddress = remoteIPAddress;
38+
RemotePort = remotePort;
39+
State = state;
40+
}
41+
}
42+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System.Collections.Generic;
2+
using System.Net;
3+
using System.Net.NetworkInformation;
4+
using System.Threading.Tasks;
5+
6+
namespace NETworkManager.Models.Network
7+
{
8+
public class Listener
9+
{
10+
#region Methods
11+
public static Task<List<ListenerInfo>> GetAllActiveListenersAsync()
12+
{
13+
return Task.Run(() => GetAllActiveListeners());
14+
15+
}
16+
17+
public static List<ListenerInfo> GetAllActiveListeners()
18+
{
19+
List<ListenerInfo> list = new List<ListenerInfo>();
20+
21+
list.AddRange(GetActiveTcpListeners());
22+
list.AddRange(GetActiveUdpListeners());
23+
24+
return list;
25+
}
26+
27+
public static Task<List<ListenerInfo>> GetActiveTcpListenersAsync()
28+
{
29+
return Task.Run(() => GetActiveTcpListeners());
30+
}
31+
32+
public static List<ListenerInfo> GetActiveTcpListeners()
33+
{
34+
List<ListenerInfo> list = new List<ListenerInfo>();
35+
36+
foreach (IPEndPoint ipEndPoint in IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners())
37+
list.Add(new ListenerInfo(Protocol.TCP, ipEndPoint.Address, ipEndPoint.Port));
38+
39+
return list;
40+
}
41+
42+
public static Task<List<ListenerInfo>> GetActiveUdpListenersAsync()
43+
{
44+
return Task.Run(() => GetActiveUdpListeners());
45+
}
46+
47+
public static List<ListenerInfo> GetActiveUdpListeners()
48+
{
49+
List<ListenerInfo> list = new List<ListenerInfo>();
50+
51+
foreach (IPEndPoint ipEndPoint in IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners())
52+
list.Add(new ListenerInfo(Protocol.UDP, ipEndPoint.Address, ipEndPoint.Port));
53+
54+
return list;
55+
}
56+
#endregion
57+
58+
#region Enum
59+
public enum Protocol
60+
{
61+
TCP,
62+
UDP
63+
}
64+
65+
#endregion
66+
}
67+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using NETworkManager.Utilities;
2+
using System.Net;
3+
using static NETworkManager.Models.Network.Listener;
4+
5+
namespace NETworkManager.Models.Network
6+
{
7+
public class ListenerInfo
8+
{
9+
public Protocol Protocol { get; set; }
10+
public IPAddress IPAddress { get; set; }
11+
public int Port { get; set; }
12+
13+
public int IPAddressInt32
14+
{
15+
get { return IPAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork ? IPv4AddressHelper.ConvertToInt32(IPAddress) : 0; }
16+
}
17+
18+
public ListenerInfo()
19+
{
20+
21+
}
22+
23+
public ListenerInfo(Protocol protocol, IPAddress ipddress, int port)
24+
{
25+
Protocol = protocol;
26+
IPAddress = ipddress;
27+
Port = port;
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)