72 lines
2.7 KiB
C#
72 lines
2.7 KiB
C#
using System.Diagnostics;
|
|
using System.Windows;
|
|
using MessageBox = System.Windows.MessageBox;
|
|
|
|
namespace EonaCat.PortMonitor
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for ConnectionDetailsWindow.xaml
|
|
/// </summary>
|
|
public partial class ConnectionDetailsWindow : Window
|
|
{
|
|
private ConnectionInfo _currentConnection;
|
|
|
|
public ConnectionDetailsWindow(ConnectionInfo conn)
|
|
{
|
|
InitializeComponent();
|
|
|
|
_currentConnection = conn;
|
|
ProtocolText.Text = conn.Protocol;
|
|
LocalAddressText.Text = conn.LocalAddress;
|
|
LocalPortText.Text = conn.LocalPort.ToString();
|
|
RemoteAddressText.Text = conn.RemoteAddress;
|
|
RemotePortText.Text = conn.RemotePort.ToString();
|
|
|
|
StateText.Text = conn.State;
|
|
|
|
// Update the state text every second
|
|
System.Windows.Threading.DispatcherTimer stateTimer = new System.Windows.Threading.DispatcherTimer();
|
|
stateTimer.Interval = TimeSpan.FromSeconds(1);
|
|
stateTimer.Tick += (sender, e) => UpdateStateText(conn);
|
|
stateTimer.Start();
|
|
|
|
ProcessIdText.Text = Convert.ToString(conn.ProcessId);
|
|
ProcessNameText.Text = conn.ProcessName;
|
|
ConnectionDurationText.Text = Convert.ToString(conn.FormattedConnectionDuration);
|
|
|
|
// Update the connection duration text every second
|
|
System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
|
|
timer.Interval = TimeSpan.FromSeconds(1);
|
|
timer.Tick += (sender, e) => UpdateConnectionDurationText(conn);
|
|
timer.Start();
|
|
}
|
|
|
|
private void UpdateStateText(ConnectionInfo conn)
|
|
{
|
|
Dispatcher.Invoke(() => StateText.Text = conn.State);
|
|
}
|
|
|
|
private void UpdateConnectionDurationText(ConnectionInfo conn)
|
|
{
|
|
Dispatcher.Invoke(() => ConnectionDurationText.Text = Convert.ToString(conn.FormattedConnectionDuration));
|
|
}
|
|
|
|
private void btnProcessPath_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
// Open the process path in explorer
|
|
try
|
|
{
|
|
var process = Process.GetProcessById(_currentConnection.ProcessId);
|
|
if (process != null && process.MainModule != null)
|
|
{
|
|
Process.Start("explorer.exe", $"/select, \"{process.MainModule.FileName}\"");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"Failed to get process path: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|