Initial version

This commit is contained in:
2025-09-26 21:35:54 +02:00
parent e8975d150a
commit 737bde994b
9 changed files with 1548 additions and 41 deletions

View File

@@ -0,0 +1,9 @@
<Application x:Class="EonaCat.ConnectionMonitor.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:EonaCat.ConnectionMonitor"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

View File

@@ -0,0 +1,14 @@
using System.Configuration;
using System.Data;
using System.Windows;
namespace EonaCat.ConnectionMonitor
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

View File

@@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

View File

@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
<ApplicationIcon>EonaCat.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Resource Include="EonaCat.ico" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36414.22 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EonaCat.ConnectionMonitor", "EonaCat.ConnectionMonitor.csproj", "{A05664B4-D80B-45D2-9906-460F7C05338D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A05664B4-D80B-45D2-9906-460F7C05338D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A05664B4-D80B-45D2-9906-460F7C05338D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A05664B4-D80B-45D2-9906-460F7C05338D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A05664B4-D80B-45D2-9906-460F7C05338D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F48EE5FF-4EBA-44AD-9321-3D850E3A32F1}
EndGlobalSection
EndGlobal

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 KiB

View File

@@ -0,0 +1,519 @@
<Window x:Class="EonaCat.ConnectionMonitor.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="EonaCat Connection Monitor" Height="800" Width="1400"
WindowStartupLocation="CenterScreen">
<Window.Resources>
<Style x:Key="TabItemStyle" TargetType="TabItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TabItem">
<Border Name="Border" Background="#2D2D30" BorderBrush="#3F3F46" BorderThickness="1,1,1,0" CornerRadius="4,4,0,0" Margin="0,0,2,0">
<ContentPresenter x:Name="ContentSite" VerticalAlignment="Center" HorizontalAlignment="Center"
ContentSource="Header" Margin="12,8,12,8" TextElement.Foreground="White"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Border" Property="Background" Value="#007ACC"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Border" Property="Background" Value="#3C3C3C"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="HeaderTextStyle" TargetType="TextBlock">
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="Foreground" Value="White"/>
</Style>
</Window.Resources>
<Grid Background="#1E1E1E">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- Header -->
<Border Grid.Row="0" Background="#2D2D30" BorderBrush="#3F3F46" BorderThickness="0,0,0,1" Padding="15">
<StackPanel>
<TextBlock Text="EonaCat Connection Monitor" FontSize="18" FontWeight="Bold" Foreground="White"/>
<TextBlock Text="Monitor network connections with process information and geographical data" FontSize="12" Foreground="#CCCCCC" Margin="0,2,0,0"/>
</StackPanel>
</Border>
<!-- Controls -->
<Border Grid.Row="1" Background="#252526" BorderBrush="#3F3F46" BorderThickness="0,0,0,1" Padding="15">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal">
<Button Name="btnStart" Content="Start Monitoring" Click="BtnStart_Click"
Background="#007ACC" Foreground="White" BorderBrush="#007ACC"
Padding="12,6" Margin="0,0,10,0" Cursor="Hand"/>
<Button Name="btnStop" Content="Stop Monitoring" Click="BtnStop_Click"
Background="#D83B01" Foreground="White" BorderBrush="#D83B01"
Padding="12,6" Margin="0,0,10,0" IsEnabled="False" Cursor="Hand"/>
<Button Name="btnRefresh" Content="Refresh" Click="BtnRefresh_Click"
Background="#6C757D" Foreground="White" BorderBrush="#6C757D"
Padding="12,6" Cursor="Hand"/>
</StackPanel>
<StackPanel Grid.Column="2" Orientation="Horizontal">
<TextBlock Text="Filter:" VerticalAlignment="Center" Foreground="White" Margin="0,0,5,0"/>
<TextBox Name="txtFilter" Width="200" Height="25"
Background="#3C3C3C" Foreground="White" BorderBrush="#5A5A5A"
TextChanged="TxtFilter_TextChanged"/>
</StackPanel>
<StackPanel Grid.Column="3" Orientation="Horizontal" Margin="15,0,0,0">
<TextBlock Text="Auto Refresh:" VerticalAlignment="Center" Foreground="White" Margin="0,0,5,0"/>
<CheckBox Name="chkAutoRefresh" IsChecked="True" VerticalAlignment="Center"
Foreground="White" Checked="ChkAutoRefresh_Checked" Unchecked="ChkAutoRefresh_Unchecked"/>
</StackPanel>
<TextBlock Grid.Column="4" Name="lblStatus" Text="Ready" VerticalAlignment="Center"
Foreground="#CCCCCC" Margin="15,0,0,0"/>
</Grid>
</Border>
<!-- Main Content -->
<TabControl Grid.Row="2" Background="#1E1E1E" BorderBrush="#3F3F46" Style="{x:Null}">
<TabItem Header="All Connections" Style="{StaticResource TabItemStyle}">
<Grid Background="#1E1E1E">
<DataGrid Name="dgAllConnections"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.VirtualizationMode="Recycling"
EnableRowVirtualization="True"
EnableColumnVirtualization="True"
ScrollViewer.CanContentScroll="True"
AutoGenerateColumns="False"
Background="#1E1E1E"
Foreground="White"
GridLinesVisibility="Horizontal"
HorizontalGridLinesBrush="#3F3F46"
HeadersVisibility="Column"
CanUserAddRows="False"
IsReadOnly="True"
AlternatingRowBackground="#2D2D30"
RowBackground="#1E1E1E">
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="Background" Value="#2D2D30"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Padding" Value="8"/>
<Setter Property="BorderBrush" Value="#3F3F46"/>
<Setter Property="BorderThickness" Value="0,0,1,1"/>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Process" Binding="{Binding ProcessName}" Width="Auto"/>
<DataGridTextColumn Header="PID" Binding="{Binding ProcessId}" Width="60"/>
<DataGridTextColumn Header="Protocol" Binding="{Binding Protocol}" Width="80"/>
<DataGridTextColumn Header="Local Address" Binding="{Binding LocalEndPoint}" Width="150"/>
<DataGridTextColumn Header="Remote Address" Binding="{Binding RemoteEndPoint}" Width="150"/>
<DataGridTextColumn Header="State" Binding="{Binding State}" Width="100">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Padding" Value="4,2"/>
<Style.Triggers>
<DataTrigger Binding="{Binding State}" Value="ESTABLISHED">
<Setter Property="Background" Value="#218838"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="SYN_SENT">
<Setter Property="Background" Value="#E0A800"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="SYN_RECEIVED">
<Setter Property="Background" Value="#C69500"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="FIN_WAIT_1">
<Setter Property="Background" Value="#CC8400"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="FIN_WAIT_2">
<Setter Property="Background" Value="#B26B00"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="CLOSE_WAIT">
<Setter Property="Background" Value="#D43F00"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="CLOSING">
<Setter Property="Background" Value="#E55535"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="LAST_ACK">
<Setter Property="Background" Value="#E55535"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="TIME_WAIT">
<Setter Property="Background" Value="#B8860B"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="CLOSED">
<Setter Property="Background" Value="#5A6268"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="LISTENING">
<Setter Property="Background" Value="#138496"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="UDP">
<Setter Property="Background" Value="#520DC2"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTemplateColumn Header="Country" Width="80">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding CountryFlagImage}" Width="24" Height="16" Margin="0,0,5,0"/>
<TextBlock Text="{Binding CountryCode}" VerticalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Country Name" Binding="{Binding CountryName}" Width="120"/>
<DataGridTextColumn Header="ISP" Binding="{Binding ISP}" Width="150"/>
<DataGridTextColumn Header="Start Time" Binding="{Binding StartTime, StringFormat=HH:mm:ss}" Width="Auto"/>
<DataGridTextColumn Header="Duration" Binding="{Binding Duration, StringFormat=c}" Width="Auto"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</TabItem>
<TabItem Header="Configured Connections" Style="{StaticResource TabItemStyle}">
<Grid Background="#1E1E1E">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" Background="#252526" BorderBrush="#3F3F46" BorderThickness="0,0,0,1" Padding="10">
<StackPanel Orientation="Horizontal">
<Button Name="btnLoadConfig" Content="Load Config" Click="BtnLoadConfig_Click"
Background="#28A745" Foreground="White" BorderBrush="#28A745"
Padding="10,5" Margin="0,0,10,0" Cursor="Hand"/>
<Button Name="btnSaveConfig" Content="Save Config" Click="BtnSaveConfig_Click"
Background="#FFC107" Foreground="Black" BorderBrush="#FFC107"
Padding="10,5" Cursor="Hand"/>
</StackPanel>
</Border>
<DataGrid Grid.Row="1" Name="dgConfiguredConnections" AutoGenerateColumns="False"
Background="#1E1E1E" Foreground="White"
GridLinesVisibility="Horizontal" HorizontalGridLinesBrush="#3F3F46"
HeadersVisibility="Column" CanUserAddRows="True"
AlternatingRowBackground="#2D2D30" RowBackground="#1E1E1E">
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="Background" Value="#2D2D30"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Padding" Value="8"/>
<Setter Property="BorderBrush" Value="#3F3F46"/>
<Setter Property="BorderThickness" Value="0,0,1,1"/>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Display Name" Binding="{Binding DisplayName}" Width="200"/>
<DataGridTextColumn Header="IP Address" Binding="{Binding IpAddress}" Width="150"/>
<DataGridTextColumn Header="Port" Binding="{Binding Port}" Width="80"/>
<DataGridTextColumn Header="Status" Binding="{Binding Status}" Width="100"/>
<DataGridTextColumn Header="Process" Binding="{Binding ProcessName}" Width="Auto"/>
<DataGridTextColumn Header="Last Seen" Binding="{Binding LastSeen}" Width="150"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</TabItem>
<TabItem Header="Connection History" Style="{StaticResource TabItemStyle}">
<Grid Background="#1E1E1E">
<DataGrid x:Name="connectionHistoryDataGrid"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.VirtualizationMode="Recycling"
EnableRowVirtualization="True"
EnableColumnVirtualization="True"
ScrollViewer.CanContentScroll="True"
AutoGenerateColumns="False"
Background="#1E1E1E"
Foreground="White"
GridLinesVisibility="Horizontal"
HorizontalGridLinesBrush="#3F3F46"
HeadersVisibility="Column"
CanUserAddRows="False"
IsReadOnly="True"
AlternatingRowBackground="#2D2D30"
RowBackground="#1E1E1E">
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="Background" Value="#2D2D30"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Padding" Value="8"/>
<Setter Property="BorderBrush" Value="#3F3F46"/>
<Setter Property="BorderThickness" Value="0,0,1,1"/>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Process" Binding="{Binding ProcessName}" Width="Auto"/>
<DataGridTextColumn Header="PID" Binding="{Binding ProcessId}" Width="60"/>
<DataGridTextColumn Header="Protocol" Binding="{Binding Protocol}" Width="80"/>
<DataGridTextColumn Header="Local Address" Binding="{Binding LocalEndPoint}" Width="150"/>
<DataGridTextColumn Header="Remote Address" Binding="{Binding RemoteEndPoint}" Width="150"/>
<DataGridTextColumn Header="State" Binding="{Binding State}" Width="100">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Padding" Value="4,2"/>
<Style.Triggers>
<DataTrigger Binding="{Binding State}" Value="ESTABLISHED">
<Setter Property="Background" Value="#218838"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="SYN_SENT">
<Setter Property="Background" Value="#E0A800"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="SYN_RECEIVED">
<Setter Property="Background" Value="#C69500"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="FIN_WAIT_1">
<Setter Property="Background" Value="#CC8400"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="FIN_WAIT_2">
<Setter Property="Background" Value="#B26B00"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="CLOSE_WAIT">
<Setter Property="Background" Value="#D43F00"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="CLOSING">
<Setter Property="Background" Value="#E55535"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="LAST_ACK">
<Setter Property="Background" Value="#E55535"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="TIME_WAIT">
<Setter Property="Background" Value="#B8860B"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="CLOSED">
<Setter Property="Background" Value="#5A6268"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="LISTENING">
<Setter Property="Background" Value="#138496"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="UDP">
<Setter Property="Background" Value="#520DC2"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTemplateColumn Header="Country" Width="80">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding CountryFlagImage}" Width="24" Height="16" Margin="0,0,5,0"/>
<TextBlock Text="{Binding CountryCode}" VerticalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Country Name" Binding="{Binding CountryName}" Width="120"/>
<DataGridTextColumn Header="ISP" Binding="{Binding ISP}" Width="150"/>
<DataGridTextColumn Header="Start Time" Binding="{Binding StartTime, StringFormat=HH:mm:ss}" Width="Auto"/>
<DataGridTextColumn Header="End Time" Binding="{Binding EndTime, StringFormat=HH:mm:ss}" Width="Auto"/>
<DataGridTextColumn Header="Duration" Binding="{Binding Duration, StringFormat=c}" Width="Auto"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</TabItem>
<TabItem Header="Connection Events" Style="{StaticResource TabItemStyle}">
<DataGrid x:Name="dgConnectionEvents" AutoGenerateColumns="False"
Background="#1E1E1E" Foreground="White"
GridLinesVisibility="Horizontal" HorizontalGridLinesBrush="#3F3F46"
HeadersVisibility="Column" CanUserAddRows="False" IsReadOnly="True"
AlternatingRowBackground="#2D2D30" RowBackground="#1E1E1E">
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="Background" Value="#2D2D30"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Padding" Value="8"/>
<Setter Property="BorderBrush" Value="#3F3F46"/>
<Setter Property="BorderThickness" Value="0,0,1,1"/>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Timestamp" Binding="{Binding Timestamp, StringFormat=HH:mm:ss}" Width="Auto"/>
<DataGridTextColumn Header="Event" Binding="{Binding EventType}" Width="Auto"/>
<DataGridTextColumn Header="Process" Binding="{Binding ProcessName}" Width="150"/>
<DataGridTextColumn Header="PID" Binding="{Binding ProcessId}" Width="60"/>
<DataGridTextColumn Header="Protocol" Binding="{Binding Protocol}" Width="80"/>
<DataGridTextColumn Header="Local Address" Binding="{Binding LocalEndPoint}" Width="150"/>
<DataGridTextColumn Header="Remote Address" Binding="{Binding RemoteEndPoint}" Width="150"/>
<DataGridTextColumn Header="State" Binding="{Binding State}" Width="100">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Padding" Value="4,2"/>
<Style.Triggers>
<DataTrigger Binding="{Binding State}" Value="ESTABLISHED">
<Setter Property="Background" Value="#218838"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="SYN_SENT">
<Setter Property="Background" Value="#E0A800"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="SYN_RECEIVED">
<Setter Property="Background" Value="#C69500"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="FIN_WAIT_1">
<Setter Property="Background" Value="#CC8400"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="FIN_WAIT_2">
<Setter Property="Background" Value="#B26B00"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="CLOSE_WAIT">
<Setter Property="Background" Value="#D43F00"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="CLOSING">
<Setter Property="Background" Value="#E55535"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="LAST_ACK">
<Setter Property="Background" Value="#E55535"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="TIME_WAIT">
<Setter Property="Background" Value="#B8860B"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="CLOSED">
<Setter Property="Background" Value="#5A6268"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="LISTENING">
<Setter Property="Background" Value="#138496"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="UDP">
<Setter Property="Background" Value="#520DC2"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</TabItem>
<TabItem Header="Statistics" Style="{StaticResource TabItemStyle}">
<Grid Background="#1E1E1E" Margin="20">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="0,0,0,20">
<Border Background="#2D2D30" CornerRadius="5" Padding="15" Margin="0,0,15,0">
<StackPanel>
<TextBlock Text="Total Connections" Style="{StaticResource HeaderTextStyle}"/>
<TextBlock Name="lblTotalConnections" Text="0" FontSize="24" Foreground="#007ACC" FontWeight="Bold"/>
</StackPanel>
</Border>
<Border Background="#2D2D30" CornerRadius="5" Padding="15" Margin="0,0,15,0">
<StackPanel>
<TextBlock Text="Established" Style="{StaticResource HeaderTextStyle}"/>
<TextBlock Name="lblEstablishedConnections" Text="0" FontSize="24" Foreground="#28A745" FontWeight="Bold"/>
</StackPanel>
</Border>
<Border Background="#2D2D30" CornerRadius="5" Padding="15" Margin="0,0,15,0">
<StackPanel>
<TextBlock Text="Listening" Style="{StaticResource HeaderTextStyle}"/>
<TextBlock Name="lblListeningConnections" Text="0" FontSize="24" Foreground="#FFC107" FontWeight="Bold"/>
</StackPanel>
</Border>
<Border Background="#2D2D30" CornerRadius="5" Padding="15">
<StackPanel>
<TextBlock Text="Unique Countries" Style="{StaticResource HeaderTextStyle}"/>
<TextBlock Name="lblUniqueCountries" Text="0" FontSize="24" Foreground="#17A2B8" FontWeight="Bold"/>
</StackPanel>
</Border>
</StackPanel>
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
<StackPanel>
<TextBlock Text="Top Processes by Connection Count" Style="{StaticResource HeaderTextStyle}" Margin="0,0,0,10"/>
<DataGrid Name="dgProcessStats" AutoGenerateColumns="False"
Background="#1E1E1E" Foreground="White" Height="200"
GridLinesVisibility="Horizontal" HorizontalGridLinesBrush="#3F3F46"
HeadersVisibility="Column" CanUserAddRows="False" IsReadOnly="True"
AlternatingRowBackground="#2D2D30" RowBackground="#1E1E1E">
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="Background" Value="#2D2D30"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Padding" Value="8"/>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Process Name" Binding="{Binding ProcessName}" Width="200"/>
<DataGridTextColumn Header="Connection Count" Binding="{Binding ConnectionCount}" Width="120"/>
<DataGridTextColumn Header="Unique IPs" Binding="{Binding UniqueIPs}" Width="100"/>
</DataGrid.Columns>
</DataGrid>
<TextBlock Text="Countries by Connection Count" Style="{StaticResource HeaderTextStyle}" Margin="0,20,0,10"/>
<DataGrid Name="dgCountryStats" AutoGenerateColumns="False"
Background="#1E1E1E" Foreground="White" Height="200"
GridLinesVisibility="Horizontal" HorizontalGridLinesBrush="#3F3F46"
HeadersVisibility="Column" CanUserAddRows="False" IsReadOnly="True"
AlternatingRowBackground="#2D2D30" RowBackground="#1E1E1E">
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="Background" Value="#2D2D30"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Padding" Value="8"/>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.Columns>
<DataGridTemplateColumn Header="Flag" Width="60">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding FlagUrl}" Width="24" Height="16"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Country" Binding="{Binding CountryName}" Width="150"/>
<DataGridTextColumn Header="Connections" Binding="{Binding ConnectionCount}" Width="100"/>
</DataGrid.Columns>
</DataGrid>
</StackPanel>
</ScrollViewer>
</Grid>
</TabItem>
</TabControl>
<!-- Status Bar -->
<StatusBar Grid.Row="3" Background="#2D2D30" BorderBrush="#3F3F46" BorderThickness="0,1,0,0">
<StatusBarItem>
<TextBlock Name="lblStatusBar" Text="Ready" Foreground="White"/>
</StatusBarItem>
<Separator/>
<StatusBarItem>
<TextBlock Name="lblLastUpdate" Text="Last Update: Never" Foreground="#CCCCCC"/>
</StatusBarItem>
</StatusBar>
</Grid>
</Window>

View File

@@ -0,0 +1,783 @@
using Microsoft.Win32;
using System.Collections.Concurrent;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.NetworkInformation;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
namespace EonaCat.ConnectionMonitor
{
public partial class MainWindow : Window
{
private ObservableCollection<ConnectionInfo> _connectionHistory;
private DispatcherTimer _refreshTimer;
private ObservableCollection<ConnectionInfo> _allConnections;
private ObservableCollection<ConfiguredConnection> _configuredConnections;
private ObservableCollection<ProcessStatistic> _processStats;
private ObservableCollection<CountryStatistic> _countryStats;
private ObservableCollection<ConnectionEvent> _connectionEvents;
private CollectionViewSource _allConnectionsView;
private string _configFilePath = "connections_config.json";
private bool _isMonitoring = false;
private HttpClient _httpClient;
private bool _isRefreshing;
private readonly ConcurrentDictionary<string, GeolocationInfo> _geoCache = new();
private string _connectionEventsLogPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ConnectionEvents.log");
public MainWindow()
{
InitializeComponent();
//Icon = BitmapFrame.Create(new Uri("pack://application:,,,/Resources/app_icon.ico", UriKind.Absolute));
InitializeCollections();
InitializeTimer();
_httpClient = new HttpClient();
LoadConfigurationAsync().ConfigureAwait(false);
}
private void InitializeCollections()
{
_allConnections = new ObservableCollection<ConnectionInfo>();
_configuredConnections = new ObservableCollection<ConfiguredConnection>();
_processStats = new ObservableCollection<ProcessStatistic>();
_countryStats = new ObservableCollection<CountryStatistic>();
_connectionHistory = new ObservableCollection<ConnectionInfo>();
_connectionEvents = new ObservableCollection<ConnectionEvent>();
_allConnectionsView = new CollectionViewSource { Source = _allConnections };
dgAllConnections.ItemsSource = _allConnectionsView.View;
dgConfiguredConnections.ItemsSource = _configuredConnections;
dgProcessStats.ItemsSource = _processStats;
dgCountryStats.ItemsSource = _countryStats;
connectionHistoryDataGrid.ItemsSource = _connectionHistory;
dgConnectionEvents.ItemsSource = _connectionEvents;
}
private void InitializeTimer()
{
_refreshTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(5) };
_refreshTimer.Tick += RefreshTimer_Tick;
}
private async void RefreshTimer_Tick(object sender, EventArgs e)
{
await RefreshConnectionsAsync();
}
private void BtnStart_Click(object sender, RoutedEventArgs e)
{
StartMonitoring();
}
private void BtnStop_Click(object sender, RoutedEventArgs e)
{
StopMonitoring();
}
private async void BtnRefresh_Click(object sender, RoutedEventArgs e)
{
await RefreshConnectionsAsync();
}
private void TxtFilter_TextChanged(object sender, TextChangedEventArgs e)
{
ApplyFilter();
}
private void ChkAutoRefresh_Checked(object sender, RoutedEventArgs e)
{
if (_isMonitoring && chkAutoRefresh.IsChecked == true)
{
_refreshTimer.Start();
}
}
private void ChkAutoRefresh_Unchecked(object sender, RoutedEventArgs e)
{
_refreshTimer.Stop();
}
private void StartMonitoring()
{
_isMonitoring = true;
btnStart.IsEnabled = false;
btnStop.IsEnabled = true;
lblStatus.Text = "Monitoring...";
if (chkAutoRefresh.IsChecked == true)
{
_refreshTimer.Start();
}
RefreshConnectionsAsync().ConfigureAwait(false);
}
private void StopMonitoring()
{
_isMonitoring = false;
_refreshTimer.Stop();
btnStart.IsEnabled = true;
btnStop.IsEnabled = false;
lblStatus.Text = "Stopped";
}
private readonly string _geoCacheFilePath = "geo_cache.json";
private async Task SaveGeoCacheAsync()
{
try
{
var dict = _geoCache.ToDictionary(k => k.Key, v => v.Value);
var json = JsonSerializer.Serialize(dict, new JsonSerializerOptions { WriteIndented = true });
await File.WriteAllTextAsync(_geoCacheFilePath, json);
}
catch { }
}
private async Task RefreshConnectionsAsync()
{
if (_isRefreshing) return;
_isRefreshing = true;
try
{
Dispatcher.Invoke(() => lblStatus.Text = "Refreshing...");
var connections = await Task.Run(async () =>
{
var result = new List<ConnectionInfo>();
var ipProps = IPGlobalProperties.GetIPGlobalProperties();
var tcpConnections = ipProps.GetActiveTcpConnections();
var tcpListeners = ipProps.GetActiveTcpListeners();
var udpListeners = ipProps.GetActiveUdpListeners();
var pidToProcessName = Process.GetProcesses().ToDictionary(p => p.Id, p => p.ProcessName);
var tasks = new List<Task<ConnectionInfo>>();
tasks.AddRange(tcpConnections.Select(c =>
CreateInfoAsync(
c.LocalEndPoint,
c.RemoteEndPoint,
"TCP",
FormatTcpState(c.State),
pidToProcessName)));
tasks.AddRange(tcpListeners.Select(l =>
CreateInfoAsync(l, null, "TCP", "LISTENING", pidToProcessName)));
tasks.AddRange(udpListeners.Select(l =>
CreateInfoAsync(l, null, "UDP", "LISTENING", pidToProcessName)));
var infos = await Task.WhenAll(tasks);
result.AddRange(infos.Where(c => c != null));
return result;
});
// Remove duplicates
connections = connections
.GroupBy(c => $"{c.Protocol}|{c.LocalEndPoint}|{c.RemoteEndPoint}|{c.State}")
.Select(g => g.First())
.ToList();
// Geolocation
var ipsToFetch = connections
.Where(c => c.RemoteEndPoint != "N/A")
.Select(c => c.RemoteEndPoint.Split(':')[0])
.Where(ip => !_geoCache.ContainsKey(ip))
.Distinct()
.ToList();
var semaphore = new SemaphoreSlim(10);
var geoTasks = ipsToFetch.Select(async ip =>
{
await semaphore.WaitAsync();
try
{
var geo = await GetGeolocationInfoAsync(ip);
if (geo != null)
_geoCache[ip] = geo;
}
finally { semaphore.Release(); }
});
await Task.WhenAll(geoTasks);
foreach (var conn in connections)
{
if (conn.RemoteEndPoint != "N/A")
{
var ip = conn.RemoteEndPoint.Split(':')[0];
if (_geoCache.TryGetValue(ip, out var geo))
{
conn.CountryCode = geo.CountryCode;
conn.CountryName = geo.CountryName;
conn.ISP = geo.ISP;
conn.CountryFlagUrl = GetFlagUrl(geo.CountryCode)?.ToString();
}
}
}
// Track new and disconnected connections by state
var currentKeys = connections
.Select(c => $"{c.Protocol}|{c.LocalEndPoint}|{c.RemoteEndPoint}|{c.State}")
.ToHashSet();
var previousKeys = _allConnections
.Select(c => $"{c.Protocol}|{c.LocalEndPoint}|{c.RemoteEndPoint}|{c.State}")
.ToHashSet();
// New connections
var newConnections = connections.Where(c => !previousKeys.Contains(
$"{c.Protocol}|{c.LocalEndPoint}|{c.RemoteEndPoint}|{c.State}")).ToList();
foreach (var conn in newConnections)
{
conn.StartTime = DateTime.Now;
conn.LastSeen = DateTime.Now;
_allConnections.Add(conn);
_connectionHistory.Add(new ConnectionInfo
{
ProcessName = conn.ProcessName,
ProcessId = conn.ProcessId,
Protocol = conn.Protocol,
LocalEndPoint = conn.LocalEndPoint,
RemoteEndPoint = conn.RemoteEndPoint,
State = /*conn.Protocol == "UDP" ? "UDP" :*/ conn.State.ToUpperInvariant(),
CountryCode = conn.CountryCode,
CountryName = conn.CountryName,
CountryFlagUrl = conn.CountryFlagUrl,
ISP = conn.ISP,
StartTime = conn.StartTime,
LastSeen = conn.LastSeen,
UniqueId = conn.UniqueId
});
LogConnectionEvent(conn, $"Connected ({conn.State})");
}
// Disconnected or state-changed connections
foreach (var conn in _allConnections)
{
// Update LastSeen for duration calculation
conn.LastSeen = DateTime.Now;
// Check if connection still exists in current scan
var key = $"{conn.Protocol}|{conn.LocalEndPoint}|{conn.RemoteEndPoint}|{conn.State}";
if (!currentKeys.Contains(key))
{
LogConnectionEvent(conn, $"Disconnected ({conn.State})");
}
}
// Remove old connections not in the new list
for (int i = _allConnections.Count - 1; i >= 0; i--)
{
var key = $"{_allConnections[i].Protocol}|{_allConnections[i].LocalEndPoint}|{_allConnections[i].RemoteEndPoint}|{_allConnections[i].State}";
if (!currentKeys.Contains(key))
_allConnections.RemoveAt(i);
}
// Preserve selection
var selectedIds = dgAllConnections.SelectedItems
.OfType<ConnectionInfo>()
.Select(c => c.UniqueId)
.ToHashSet();
dgAllConnections.SelectedItems.Clear();
foreach (var conn in _allConnections)
{
if (selectedIds.Contains(conn.UniqueId))
dgAllConnections.SelectedItems.Add(conn);
}
Dispatcher.Invoke(() =>
{
UpdateConfiguredConnections();
UpdateStatistics();
lblStatus.Text = $"Found {_allConnections.Count} connections";
lblLastUpdate.Text = $"Last Update: {DateTime.Now:HH:mm:ss}";
});
_ = SaveGeoCacheAsync();
}
catch (Exception ex)
{
Dispatcher.Invoke(() => lblStatus.Text = $"Error: {ex.Message}");
}
finally
{
_isRefreshing = false;
}
}
private void LogConnectionEvent(ConnectionInfo conn, string eventType)
{
var evt = new ConnectionEvent
{
Timestamp = DateTime.Now,
ProcessName = conn.ProcessName,
ProcessId = conn.ProcessId,
Protocol = conn.Protocol,
LocalEndPoint = conn.LocalEndPoint,
RemoteEndPoint = conn.RemoteEndPoint,
State = /*conn.Protocol == "UDP" ? "UDP" :*/ conn.State.ToUpperInvariant(),
EventType = eventType
};
Dispatcher.Invoke(() =>
{
_connectionEvents.Add(evt);
});
// Append to log
File.AppendAllLines(_connectionEventsLogPath,
new[] { $"{evt.Timestamp:yyyy-MM-dd HH:mm:ss}\t{evt.EventType}\t{evt.ProcessName}\t{evt.ProcessId}\t{evt.Protocol}\t{evt.LocalEndPoint}\t{evt.RemoteEndPoint}\t{evt.State}" });
}
private async Task<ConnectionInfo> CreateInfoAsync(
IPEndPoint local, IPEndPoint remote, string protocol,
string state, Dictionary<int, string> pidToProcessName)
{
var info = new ConnectionInfo
{
LocalEndPoint = local?.ToString(),
RemoteEndPoint = remote?.ToString() ?? "N/A",
Protocol = protocol,
State = /*protocol == "UDP" ? "UDP" : */state?.ToUpperInvariant(),
ProcessId = 0,
ProcessName = "Unknown",
CountryCode = "Local",
CountryName = "Local Network",
ISP = "Local",
CountryFlagUrl = null
};
info.UniqueId = $"{protocol}|{local?.ToString()}|{remote?.ToString()}|{state}|{Guid.NewGuid()}";
if (local != null)
{
var pid = GetProcessIdByPort(local.Port, protocol);
info.ProcessId = pid;
if (pidToProcessName.TryGetValue(pid, out var procName))
{
info.ProcessName = procName;
}
}
return info;
}
private string FormatTcpState(TcpState state)
{
return state switch
{
TcpState.Listen => "LISTEN",
TcpState.SynSent => "SYN_SENT",
TcpState.SynReceived => "SYN_RECEIVED",
TcpState.Established => "ESTABLISHED",
TcpState.FinWait1 => "FIN_WAIT_1",
TcpState.FinWait2 => "FIN_WAIT_2",
TcpState.CloseWait => "CLOSE_WAIT",
TcpState.Closing => "CLOSING",
TcpState.LastAck => "LAST_ACK",
TcpState.TimeWait => "TIME_WAIT",
TcpState.Closed => "CLOSED",
TcpState.DeleteTcb => "DELETE_TCB",
_ => state.ToString().ToUpperInvariant()
};
}
private int GetProcessIdByPort(int port, string protocol)
{
try
{
var startInfo = new ProcessStartInfo
{
FileName = "netstat",
Arguments = "-ano",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
};
using var process = Process.Start(startInfo);
var output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
foreach (var line in output.Split('\n'))
{
if (line.Contains(protocol))
{
var parts = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length > 4 && int.TryParse(parts.Last(), out int pid))
{
var p = int.Parse(parts[1].Split(':').Last());
if (p == port)
{
return pid;
}
}
}
}
}
catch { }
return 0;
}
private async Task<GeolocationInfo> GetGeolocationInfoAsync(string ipAddress)
{
try
{
var response = await _httpClient.GetStringAsync($"http://ip-api.com/json/{ipAddress}");
var root = JsonDocument.Parse(response).RootElement;
if (root.GetProperty("status").GetString() == "success")
{
return new GeolocationInfo
{
CountryCode = root.GetProperty("countryCode").GetString(),
CountryName = root.GetProperty("country").GetString(),
ISP = root.GetProperty("isp").GetString()
};
}
}
catch { }
return null;
}
private Uri GetFlagUrl(string countryCode)
{
if (string.IsNullOrEmpty(countryCode) || countryCode == "Local")
{
return null;
}
return new Uri($"https://flagcdn.com/16x12/{countryCode.ToLower()}.png", UriKind.Absolute);
}
private void UpdateConfiguredConnections()
{
foreach (var configured in _configuredConnections)
{
var match = _allConnections.FirstOrDefault(c =>
c.RemoteEndPoint.Contains(configured.IpAddress) &&
c.RemoteEndPoint.Contains($":{configured.Port}"));
if (match != null)
{
configured.Status = "Active";
configured.ProcessName = match.ProcessName;
configured.LastSeen = DateTime.Now;
}
else
{
configured.Status = "Inactive";
}
}
}
private void UpdateStatistics()
{
lblTotalConnections.Text = _allConnections.Count.ToString();
lblEstablishedConnections.Text = _allConnections.Count(c => c.State == "ESTABLISHED").ToString();
lblListeningConnections.Text = _allConnections.Count(c => c.State == "LISTENING").ToString();
lblUniqueCountries.Text = _allConnections
.Where(c => !string.IsNullOrEmpty(c.CountryCode) && c.CountryCode != "Local")
.Select(c => c.CountryCode).Distinct().Count().ToString();
_processStats.Clear();
var processGroups = _allConnections
.Where(c => !string.IsNullOrEmpty(c.ProcessName))
.GroupBy(c => c.ProcessName)
.OrderByDescending(g => g.Count())
.Take(10);
foreach (var g in processGroups)
{
_processStats.Add(new ProcessStatistic
{
ProcessName = g.Key,
ConnectionCount = g.Count(),
UniqueIPs = g.Where(c => c.RemoteEndPoint != "N/A")
.Select(c => c.RemoteEndPoint.Split(':')[0])
.Distinct().Count()
});
}
_countryStats.Clear();
var countryGroups = _allConnections
.Where(c => !string.IsNullOrEmpty(c.CountryCode) && c.CountryCode != "Local")
.GroupBy(c => new { c.CountryCode, c.CountryName, c.CountryFlagUrl })
.OrderByDescending(g => g.Count())
.Take(10);
foreach (var g in countryGroups)
{
_countryStats.Add(new CountryStatistic
{
CountryCode = g.Key.CountryCode,
CountryName = g.Key.CountryName,
FlagUrl = g.Key.CountryFlagUrl,
ConnectionCount = g.Count()
});
}
}
private void ApplyFilter()
{
var filterText = txtFilter.Text ?? string.Empty;
if (string.IsNullOrWhiteSpace(filterText))
{
_allConnectionsView.View.Filter = null;
}
else
{
_allConnectionsView.View.Filter = item =>
{
if (item is not ConnectionInfo connection)
{
return false;
}
return ContainsIgnoreCase(connection.ProcessName, filterText) ||
ContainsIgnoreCase(connection.LocalEndPoint, filterText) ||
ContainsIgnoreCase(connection.RemoteEndPoint, filterText) ||
ContainsIgnoreCase(connection.State, filterText) ||
ContainsIgnoreCase(connection.CountryName, filterText) ||
ContainsIgnoreCase(connection.ISP, filterText);
};
}
_allConnectionsView.View.Refresh();
}
private static bool ContainsIgnoreCase(string source, string filter) =>
!string.IsNullOrEmpty(source) && source.IndexOf(filter, System.StringComparison.OrdinalIgnoreCase) >= 0;
private async void BtnLoadConfig_Click(object sender, RoutedEventArgs e)
{
var openFileDialog = new OpenFileDialog
{
Filter = "JSON files (*.json)|*.json|All files (*.*)|*.*",
Title = "Load Configuration"
};
if (openFileDialog.ShowDialog() == true)
{
_configFilePath = openFileDialog.FileName;
await LoadConfigurationAsync();
}
}
private async void BtnSaveConfig_Click(object sender, RoutedEventArgs e)
{
var saveFileDialog = new SaveFileDialog
{
Filter = "JSON files (*.json)|*.json|All files (*.*)|*.*",
Title = "Save Configuration",
FileName = _configFilePath
};
if (saveFileDialog.ShowDialog() == true)
{
_configFilePath = saveFileDialog.FileName;
await SaveConfigurationAsync();
}
}
private async Task LoadConfigurationAsync()
{
try
{
if (!File.Exists(_configFilePath))
{
// Create default configuration
var defaultConfig = new List<ConfiguredConnection>
{
new ConfiguredConnection { DisplayName = "Google DNS", IpAddress = "8.8.8.8", Port = 53 },
new ConfiguredConnection { DisplayName = "Cloudflare DNS", IpAddress = "1.1.1.1", Port = 53 },
new ConfiguredConnection { DisplayName = "Microsoft Update", IpAddress = "13.107.42.14", Port = 443 }
};
var json = JsonSerializer.Serialize(defaultConfig, new JsonSerializerOptions { WriteIndented = true });
await File.WriteAllTextAsync(_configFilePath, json);
}
var configJson = await File.ReadAllTextAsync(_configFilePath);
var configurations = JsonSerializer.Deserialize<List<ConfiguredConnection>>(configJson);
_configuredConnections.Clear();
foreach (var config in configurations)
{
_configuredConnections.Add(config);
}
lblStatusBar.Text = $"Configuration loaded from {_configFilePath}";
}
catch (Exception ex)
{
MessageBox.Show($"Error loading configuration: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private async Task SaveConfigurationAsync()
{
try
{
var configurations = _configuredConnections.ToList();
var json = JsonSerializer.Serialize(configurations, new JsonSerializerOptions { WriteIndented = true });
await File.WriteAllTextAsync(_configFilePath, json);
lblStatusBar.Text = $"Configuration saved to {_configFilePath}";
}
catch (Exception ex)
{
MessageBox.Show($"Error saving configuration: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
protected override void OnClosing(CancelEventArgs e)
{
_refreshTimer?.Stop();
_httpClient?.Dispose();
base.OnClosing(e);
}
}
public class ConnectionInfo : INotifyPropertyChanged
{
public string ProcessName { get; set; }
public int ProcessId { get; set; }
public string Protocol { get; set; }
public string LocalEndPoint { get; set; }
public string RemoteEndPoint { get; set; }
public string State { get; set; }
public string CountryCode { get; set; }
public string CountryName { get; set; }
public string CountryFlagUrl { get; set; }
public string ISP { get; set; }
public string UniqueId { get; set; }
private DateTime? _startTime;
public DateTime? StartTime
{
get => _startTime;
set
{
_startTime = value;
OnPropertyChanged(nameof(StartTime));
OnPropertyChanged(nameof(Duration));
}
}
private DateTime? _lastSeen;
public DateTime? LastSeen
{
get => _lastSeen;
set
{
_lastSeen = value;
OnPropertyChanged(nameof(LastSeen));
OnPropertyChanged(nameof(Duration));
}
}
public TimeSpan? Duration => (StartTime != null && LastSeen != null) ? LastSeen - StartTime : null;
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName) =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
private BitmapImage _flagImage;
public BitmapImage CountryFlagImage
{
get
{
if (_flagImage != null)
{
return _flagImage;
}
if (string.IsNullOrEmpty(CountryFlagUrl))
{
return null;
}
try
{
var img = new BitmapImage();
img.BeginInit();
img.UriSource = new Uri(CountryFlagUrl);
img.CacheOption = BitmapCacheOption.OnLoad;
img.EndInit();
if (img.IsFrozen == false && img.CanFreeze)
{
img.Freeze();
}
_flagImage = img;
return _flagImage;
}
catch
{
return null;
}
}
}
}
public class ConnectionEvent
{
public string ProcessName { get; set; }
public int ProcessId { get; set; }
public string Protocol { get; set; }
public string LocalEndPoint { get; set; }
public string RemoteEndPoint { get; set; }
public string EventType { get; set; } // "Connected" or "Disconnected"
public DateTime Timestamp { get; set; }
public string State { get; set; }
}
public class ConfiguredConnection : INotifyPropertyChanged
{
public string DisplayName { get; set; }
public string IpAddress { get; set; }
public int Port { get; set; }
public string Status { get; set; } = "Unknown";
public string ProcessName { get; set; }
public DateTime? LastSeen { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
}
public class ProcessStatistic
{
public string ProcessName { get; set; }
public int ConnectionCount { get; set; }
public int UniqueIPs { get; set; }
}
public class CountryStatistic
{
public string CountryCode { get; set; }
public string CountryName { get; set; }
public string FlagUrl { get; set; }
public int ConnectionCount { get; set; }
}
public class GeolocationInfo
{
public string CountryCode { get; set; }
public string CountryName { get; set; }
public string ISP { get; set; }
}
}

213
LICENSE
View File

@@ -1,73 +1,204 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
https://EonaCat.com/license/
1. Definitions. TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
OF SOFTWARE BY EONACAT (JEROEN SAEY)
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. 1. Definitions.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. "Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. "Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: 3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and 4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and (a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. (c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. (d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. 8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
END OF TERMS AND CONDITIONS 9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
APPENDIX: How to apply the Apache License to your work. END OF TERMS AND CONDITIONS
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. APPENDIX: How to apply the Apache License to your work.
Copyright 2025 EonaCat To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Licensed under the Apache License, Version 2.0 (the "License"); Copyright [yyyy] [name of copyright owner]
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software http://www.apache.org/licenses/LICENSE-2.0
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Unless required by applicable law or agreed to in writing, software
See the License for the specific language governing permissions and distributed under the License is distributed on an "AS IS" BASIS,
limitations under the License. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.