373 lines
11 KiB
Plaintext
373 lines
11 KiB
Plaintext
unit DNetMonMain;
|
|
|
|
interface
|
|
|
|
uses
|
|
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
|
|
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Buttons, Vcl.ComCtrls, VirtualTrees,
|
|
Vcl.StdCtrls, Vcl.Menus, Vcl.ExtCtrls, ThdNicMonitor, Tocsg.Network;
|
|
|
|
type
|
|
PNicEnt = ^TNicEnt;
|
|
TNicEnt = record
|
|
Info: TNetAdapterEnt;
|
|
bOn: Boolean;
|
|
end;
|
|
|
|
TDlgNetMonMain = class(TForm)
|
|
pcMain: TPageControl;
|
|
tabNetList: TTabSheet;
|
|
tabNetMon: TTabSheet;
|
|
popFun: TPopupMenu;
|
|
miPreventNic: TMenuItem;
|
|
pnClient: TPanel;
|
|
vtList: TVirtualStringTree;
|
|
pnTop: TPanel;
|
|
btnRefresh: TSpeedButton;
|
|
vtWlan: TVirtualStringTree;
|
|
SP1: TSplitter;
|
|
mmLog: TMemo;
|
|
pnMon: TPanel;
|
|
btnNetMon: TSpeedButton;
|
|
chPreventDescInfo: TCheckBox;
|
|
chReviveSec: TCheckBox;
|
|
edReviveSec: TEdit;
|
|
Label1: TLabel;
|
|
chPreventWireless: TCheckBox;
|
|
chPW_Public: TCheckBox;
|
|
chPW_Algo: TCheckBox;
|
|
edPW_Algo: TEdit;
|
|
edPreventDescInfo: TMemo;
|
|
chPW_Quality: TCheckBox;
|
|
edPW_Quality: TEdit;
|
|
Label2: TLabel;
|
|
chPreventNew: TCheckBox;
|
|
tInit: TTimer;
|
|
chPreventDHCP: TCheckBox;
|
|
chPW_WifiName: TCheckBox;
|
|
edPW_WifiNames: TEdit;
|
|
popFun2: TPopupMenu;
|
|
miDisconnect: TMenuItem;
|
|
procedure btnRefreshClick(Sender: TObject);
|
|
procedure vtListGetNodeDataSize(Sender: TBaseVirtualTree;
|
|
var NodeDataSize: Integer);
|
|
procedure vtListGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
|
|
Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
|
|
procedure vtListGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode;
|
|
Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle;
|
|
var HintText: string);
|
|
procedure vtListCompareNodes(Sender: TBaseVirtualTree; Node1,
|
|
Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
|
|
procedure miPreventNicClick(Sender: TObject);
|
|
procedure vtWlanGetNodeDataSize(Sender: TBaseVirtualTree;
|
|
var NodeDataSize: Integer);
|
|
procedure vtWlanGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode;
|
|
Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle;
|
|
var HintText: string);
|
|
procedure vtWlanGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
|
|
Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
|
|
procedure vtListFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
|
|
procedure vtWlanFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
|
|
procedure btnNetMonClick(Sender: TObject);
|
|
procedure tInitTimer(Sender: TObject);
|
|
procedure vtWlanContextPopup(Sender: TObject; MousePos: TPoint;
|
|
var Handled: Boolean);
|
|
procedure miDisconnectClick(Sender: TObject);
|
|
private
|
|
{ Private declarations }
|
|
ThdNicMonitor_: TThdNicMonitor;
|
|
public
|
|
{ Public declarations }
|
|
Constructor Create(aOwner: TComponent); override;
|
|
Destructor Destroy; override;
|
|
|
|
procedure RefreshWlan;
|
|
|
|
procedure process_WM_NOTI_PREVENT_NIC(var msg: TMessage); Message WM_NOTI_PREVENT_NIC;
|
|
end;
|
|
|
|
var
|
|
DlgNetMonMain: TDlgNetMonMain;
|
|
|
|
implementation
|
|
|
|
uses
|
|
Tocsg.Safe, Tocsg.VTUtil, Tocsg.Convert,
|
|
Tocsg.Driver, Tocsg.Exception, System.Math, Tocsg.Trace, EM.nduWlanAPI;
|
|
|
|
{$R *.dfm}
|
|
|
|
Constructor TDlgNetMonMain.Create(aOwner: TComponent);
|
|
begin
|
|
Inherited Create(aOwner);
|
|
ThdNicMonitor_ := nil;
|
|
pcMain.ActivePageIndex := 0;
|
|
tInit.Enabled := true;
|
|
end;
|
|
|
|
Destructor TDlgNetMonMain.Destroy;
|
|
begin
|
|
if ThdNicMonitor_ <> nil then
|
|
FreeAndNil(ThdNicMonitor_);
|
|
Inherited;
|
|
end;
|
|
|
|
procedure TDlgNetMonMain.RefreshWlan;
|
|
var
|
|
WlanInfo: TWlanInfo;
|
|
pData: PWLanEnt;
|
|
i: Integer;
|
|
begin
|
|
vtWlan.BeginUpdate;
|
|
try
|
|
VT_Clear(vtWlan);
|
|
Guard(WlanInfo, TWlanInfo.Create);
|
|
for i := 0 to WlanInfo.Count - 1 do
|
|
begin
|
|
pData := VT_AddChildData(vtWlan);
|
|
pData^ := WlanInfo[i]^;
|
|
end;
|
|
finally
|
|
vtWlan.EndUpdate;
|
|
end;
|
|
end;
|
|
|
|
procedure TDlgNetMonMain.tInitTimer(Sender: TObject);
|
|
begin
|
|
tInit.Enabled := false;
|
|
btnRefresh.Click;
|
|
end;
|
|
|
|
procedure TDlgNetMonMain.btnNetMonClick(Sender: TObject);
|
|
var
|
|
NicPrevent: TNicPrevent;
|
|
begin
|
|
if ThdNicMonitor_ = nil then
|
|
begin
|
|
ZeroMemory(@NicPrevent, SizeOf(NicPrevent));
|
|
with NicPrevent do
|
|
begin
|
|
if chPreventDescInfo.Checked then
|
|
sDescPv := Trim(edPreventDescInfo.Text);
|
|
bNewIpNic := chPreventNew.Checked;
|
|
bDHCP := chPreventDHCP.Checked;
|
|
if chReviveSec.Checked then
|
|
nReviveSec := StrToIntDef(Trim(edReviveSec.Text), 0);
|
|
bWireless := chPreventWireless.Checked;
|
|
bWPublic := chPW_Public.Checked;
|
|
if chPW_Algo.Checked then
|
|
sWAlgo := Trim(edPW_Algo.Text);
|
|
if chPW_Quality.Checked then
|
|
nWQuality := StrToIntDef(Trim(edPW_Quality.Text), 0);
|
|
if chPW_WifiName.Checked then
|
|
sWifiName := Trim(edPW_WifiNames.Text);
|
|
end;
|
|
|
|
btnNetMon.Caption := '감시/차단 중지';
|
|
mmLog.Clear;
|
|
ThdNicMonitor_ := TThdNicMonitor.Create(Handle, NicPrevent);
|
|
ThdNicMonitor_.StartThread;
|
|
end else begin
|
|
btnNetMon.Caption := '감시/차단 시작';
|
|
FreeAndNil(ThdNicMonitor_);
|
|
btnRefresh.Click;
|
|
end;
|
|
|
|
tabNetList.TabVisible := ThdNicMonitor_ = nil;
|
|
chPreventDescInfo.Enabled := tabNetList.TabVisible;
|
|
edPreventDescInfo.Enabled := chPreventDescInfo.Enabled;
|
|
chPreventNew.Enabled := chPreventDescInfo.Enabled;
|
|
chPreventDHCP.Enabled := chPreventDescInfo.Enabled;
|
|
chReviveSec.Enabled := chPreventDescInfo.Enabled;
|
|
edReviveSec.Enabled := chPreventDescInfo.Enabled;
|
|
chPreventWireless.Enabled := chPreventDescInfo.Enabled;
|
|
chPW_Public.Enabled := chPreventDescInfo.Enabled;
|
|
chPW_Algo.Enabled := chPreventDescInfo.Enabled;
|
|
edPW_Algo.Enabled := chPreventDescInfo.Enabled;
|
|
chPW_Quality.Enabled := chPreventDescInfo.Enabled;
|
|
edPW_Quality.Enabled := chPreventDescInfo.Enabled;
|
|
Label1.Enabled := chPreventDescInfo.Enabled;
|
|
Label2.Enabled := chPreventDescInfo.Enabled;
|
|
chPW_WifiName.Enabled := chPreventDescInfo.Enabled;
|
|
edPW_WifiNames.Enabled := chPreventDescInfo.Enabled;
|
|
|
|
Application.ProcessMessages;
|
|
end;
|
|
|
|
procedure TDlgNetMonMain.btnRefreshClick(Sender: TObject);
|
|
var
|
|
nic: TNetAdapterInfo;
|
|
i: Integer;
|
|
pData: PNicEnt;
|
|
begin
|
|
Guard(nic, TNetAdapterInfo.Create);
|
|
|
|
vtList.BeginUpdate;
|
|
try
|
|
VT_Clear(vtList);
|
|
|
|
nic.UpdateNetAdapterInfo;
|
|
for i := 0 to nic.Count - 1 do
|
|
begin
|
|
pData := VT_AddChildData(vtList);
|
|
pData.Info := nic[i]^;
|
|
pData.bOn := GetNicEnable(pData.Info.sDesc);
|
|
end;
|
|
VT_SortAll(vtList, 0, sdAscending);
|
|
finally
|
|
vtList.EndUpdate;
|
|
end;
|
|
RefreshWlan;
|
|
end;
|
|
|
|
procedure TDlgNetMonMain.miDisconnectClick(Sender: TObject);
|
|
var
|
|
pNode: PVirtualNode;
|
|
pData: PWLanEnt;
|
|
begin
|
|
pNode := vtWlan.GetFirstSelected;
|
|
if pNode = nil then
|
|
exit;
|
|
if MessageBox(Handle, PChar('선택한 무선 연결을 해제 하시겠습니까?'),
|
|
PChar(Caption), MB_ICONWARNING or MB_YESNO) = IDNO then exit;
|
|
|
|
pData := vtWlan.GetNodeData(pNode);
|
|
if DisconnectWIFI(pData.InterfaceGuid) then
|
|
MessageBox(Handle, PChar('연결 해제 성공'), PChar(Caption), MB_ICONINFORMATION or MB_OK)
|
|
else
|
|
MessageBox(Handle, PChar('연결 해제 실패'), PChar(Caption), MB_ICONWARNING or MB_OK);
|
|
end;
|
|
|
|
procedure TDlgNetMonMain.miPreventNicClick(Sender: TObject);
|
|
var
|
|
pNode: PVirtualNode;
|
|
pData: PNicEnt;
|
|
begin
|
|
pNode := vtList.GetFirstSelected;
|
|
if pNode = nil then
|
|
exit;
|
|
|
|
if MessageBox(Handle, PChar('계속하시겠습니까?'), PChar(Caption),
|
|
MB_ICONQUESTION or MB_YESNO) = IDNO then exit;
|
|
|
|
pData := vtList.GetNodeData(pNode);
|
|
SetNicEnable(pData.Info.sDesc, false);
|
|
btnRefresh.Click;
|
|
end;
|
|
|
|
procedure TDlgNetMonMain.vtListCompareNodes(Sender: TBaseVirtualTree; Node1,
|
|
Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
|
|
var
|
|
pData1, pData2: PNicEnt;
|
|
begin
|
|
case Column of
|
|
0 :
|
|
begin
|
|
pData1 := Sender.GetNodeData(Node1);
|
|
pData2 := Sender.GetNodeData(Node2);
|
|
Result := CompareValue(pData1.Info.dwIndex, pData2.Info.dwIndex);
|
|
end;
|
|
else Result := CompareText(vtList.Text[Node1, Column], vtList.Text[Node2, Column]);
|
|
end;
|
|
end;
|
|
|
|
procedure TDlgNetMonMain.vtListFreeNode(Sender: TBaseVirtualTree;
|
|
Node: PVirtualNode);
|
|
var
|
|
pData: PNicEnt;
|
|
begin
|
|
pData := Sender.GetNodeData(Node);
|
|
Finalize(pData^);
|
|
end;
|
|
|
|
procedure TDlgNetMonMain.vtListGetHint(Sender: TBaseVirtualTree;
|
|
Node: PVirtualNode; Column: TColumnIndex;
|
|
var LineBreakStyle: TVTTooltipLineBreakStyle; var HintText: string);
|
|
begin
|
|
HintText := vtList.Text[Node, Column];
|
|
end;
|
|
|
|
procedure TDlgNetMonMain.vtListGetNodeDataSize(Sender: TBaseVirtualTree;
|
|
var NodeDataSize: Integer);
|
|
begin
|
|
NodeDataSize := SizeOf(TNicEnt);
|
|
end;
|
|
|
|
procedure TDlgNetMonMain.vtListGetText(Sender: TBaseVirtualTree;
|
|
Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
|
|
var CellText: string);
|
|
var
|
|
pData: PNicEnt;
|
|
begin
|
|
pData := Sender.GetNodeData(Node);
|
|
|
|
case Column of
|
|
0 : CellText := IntToStr(pData.Info.dwComboIdx);
|
|
1 : CellText := BooleanToStr(pData.bOn, '연결됨', '연결안됨');
|
|
2 : CellText := pData.Info.sDesc;
|
|
3 : CellText := pData.Info.sIpAddrs;
|
|
4 : CellText := pData.Info.sMacAddr;
|
|
5 : CellText := pData.Info.sName;
|
|
6 : CellText := GetNetAdapterTypeToStr(pData.Info.dwType);
|
|
7 : CellText := BooleanToStr(pData.Info.bDHCP, 'O', 'X');
|
|
end;
|
|
end;
|
|
|
|
procedure TDlgNetMonMain.vtWlanContextPopup(Sender: TObject; MousePos: TPoint;
|
|
var Handled: Boolean);
|
|
var
|
|
pNode: PVirtualNode;
|
|
begin
|
|
pNode := vtWlan.GetNodeAt(MousePos);
|
|
miDisconnect.Visible := pNode <> nil;
|
|
end;
|
|
|
|
procedure TDlgNetMonMain.vtWlanFreeNode(Sender: TBaseVirtualTree;
|
|
Node: PVirtualNode);
|
|
var
|
|
pData: PWLanEnt;
|
|
begin
|
|
pData := Sender.GetNodeData(Node);
|
|
Finalize(pData^);
|
|
end;
|
|
|
|
procedure TDlgNetMonMain.vtWlanGetHint(Sender: TBaseVirtualTree;
|
|
Node: PVirtualNode; Column: TColumnIndex;
|
|
var LineBreakStyle: TVTTooltipLineBreakStyle; var HintText: string);
|
|
begin
|
|
HintText := vtWlan.Text[Node, Column];
|
|
end;
|
|
|
|
procedure TDlgNetMonMain.vtWlanGetNodeDataSize(Sender: TBaseVirtualTree;
|
|
var NodeDataSize: Integer);
|
|
begin
|
|
NodeDataSize := SizeOf(TWLanEnt);
|
|
end;
|
|
|
|
procedure TDlgNetMonMain.vtWlanGetText(Sender: TBaseVirtualTree;
|
|
Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
|
|
var CellText: string);
|
|
var
|
|
pData: PWLanEnt;
|
|
begin
|
|
pData := Sender.GetNodeData(Node);
|
|
|
|
case Column of
|
|
0 : CellText := IntToStr(Node.Index + 1);
|
|
1 : CellText := pData.sProfile;
|
|
2 : CellText := pData.sName;
|
|
3 : CellText := IntToStr(pData.nQuality) + ' %';
|
|
4 : CellText := BooleanToStr(pData.bSecurety, 'O', 'X');
|
|
5 : CellText := DOT11_AUTH_ALGORITHM_To_String(pData.dwAlgo1);
|
|
6 : CellText := DOT11_CIPHER_ALGORITHM_To_String(pData.dwAlgo2);
|
|
7 : CellText := pData.sBssid;
|
|
end;
|
|
end;
|
|
|
|
procedure TDlgNetMonMain.process_WM_NOTI_PREVENT_NIC(var msg: TMessage);
|
|
begin
|
|
mmLog.Lines.Add(String(msg.LParam));
|
|
end;
|
|
|
|
end.
|