-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSetupForm.cs
70 lines (59 loc) · 2.71 KB
/
SetupForm.cs
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
64
65
66
67
68
69
70
//NCShark - By AlSch092 @ Github, thanks to @Diamondo25 for MapleShark
using SharpPcap;
using SharpPcap.LibPcap;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Net.Sockets;
using System.Text;
using System.Windows.Forms;
namespace NCShark
{
public partial class SetupForm : Form
{
public SetupForm()
{
InitializeComponent();
Text = "NCShark " + Program.AssemblyVersion + ", " + Program.AssemblyCopyright;
bool selected = false;
int localAreaConnection = -1;
foreach (LibPcapLiveDevice device in LibPcapLiveDeviceList.Instance)
{
if (!device.Interface.Addresses.Exists(a => a != null && a.Addr != null && a.Addr.ipAddress != null)) continue;
int index = mInterfaceCombo.Items.Add(device.Interface.FriendlyName);
if (device.Interface.FriendlyName == "Local Area Connection") localAreaConnection = index;
if (!selected && (selected = (device.Interface.FriendlyName == Config.Instance.Interface))) mInterfaceCombo.SelectedIndex = index;
}
if (!selected && localAreaConnection >= 0) mInterfaceCombo.SelectedIndex = localAreaConnection;
else if (!selected && mInterfaceCombo.Items.Count > 0) mInterfaceCombo.SelectedIndex = 0;
mLowPortNumeric.Value = Config.Instance.LowPort;
mHighPortNumeric.Value = Config.Instance.HighPort;
}
private void mInterfaceCombo_SelectedIndexChanged(object pSender, EventArgs pArgs)
{
mOKButton.Enabled = mInterfaceCombo.SelectedIndex >= 0;
}
private void mLowPortNumeric_ValueChanged(object pSender, EventArgs pArgs)
{
if (mLowPortNumeric.Value > mHighPortNumeric.Value) mLowPortNumeric.Value = mHighPortNumeric.Value;
}
private void mHighPortNumeric_ValueChanged(object pSender, EventArgs pArgs)
{
if (mHighPortNumeric.Value < mLowPortNumeric.Value) mHighPortNumeric.Value = mLowPortNumeric.Value;
}
private void mOKButton_Click(object pSender, EventArgs pArgs)
{
Config.Instance.Protocol = (string)mProtocol.Text;
Config.Instance.Interface = (string)mInterfaceCombo.SelectedItem;
Config.Instance.LowPort = (ushort)mLowPortNumeric.Value;
Config.Instance.HighPort = (ushort)mHighPortNumeric.Value;
Config.Instance.Save();
DialogResult = DialogResult.OK;
}
private void SetupForm_Load(object sender, EventArgs e)
{
}
}
}