📄 filter.cpp
字号:
// Filter.cpp : implementation file
//
#include "stdafx.h"
#include "file_handle.h"
#include "Filter.h"
#include <pcap.h>
#include <remote-ext.h>
#include <winsock.h>
#pragma comment(lib,"wsock32")
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Filter dialog
Filter::Filter(CWnd* pParent /*=NULL*/)
: CDialog(Filter::IDD, pParent)
{
//{{AFX_DATA_INIT(Filter)
m_length = 0;
m_endDate = 0;
m_endTime = 0;
m_startDate = 0;
m_startTime = 0;
m_start = FALSE;
m_end = FALSE;
m_proto = FALSE;
m_len = FALSE;
m_b_srcip = FALSE;
m_b_srcipl = FALSE;
m_b_srciph = FALSE;
m_b_dstipl = FALSE;
m_b_dstip = FALSE;
m_b_dstiph = FALSE;
m_b_srcport = FALSE;
m_b_srcportl = FALSE;
m_b_srcporth = FALSE;
m_b_dstport = FALSE;
m_b_dstportl = FALSE;
m_b_dstporth = FALSE;
m_v_dstportl = 0;
m_v_dstporth = 0;
m_v_dstport = 0;
m_v_srcportl = 0;
m_v_srcporth = 0;
m_v_srcport = 0;
//}}AFX_DATA_INIT
}
void Filter::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Filter)
DDX_Control(pDX, IDC_EDIT8, m_e_dstport);
DDX_Control(pDX, IDC_EDIT7, m_e_dstporth);
DDX_Control(pDX, IDC_EDIT6, m_e_dstportl);
DDX_Control(pDX, IDC_EDIT3, m_e_srcport);
DDX_Control(pDX, IDC_EDIT1, m_e_srcportl);
DDX_Control(pDX, IDC_COMBO4, m_dport);
DDX_Control(pDX, IDC_COMBO3, m_sport);
DDX_Control(pDX, IDC_EDIT2, m_e_srcporth);
DDX_Control(pDX, IDC_CHECK16, m_c_dstporth);
DDX_Control(pDX, IDC_CHECK15, m_c_dstportl);
DDX_Control(pDX, IDC_CHECK13, m_c_srcporth);
DDX_Control(pDX, IDC_CHECK12, m_c_srcportl);
DDX_Control(pDX, IDC_COMBO2, m_dip);
DDX_Control(pDX, IDC_IPADDRESS6, m_v_dstip);
DDX_Control(pDX, IDC_CHECK10, m_c_dstiph);
DDX_Control(pDX, IDC_CHECK9, m_c_dstipl);
DDX_Control(pDX, IDC_IPADDRESS5, m_v_srcip);
DDX_Control(pDX, IDC_CHECK7, m_c_srciph);
DDX_Control(pDX, IDC_CHECK6, m_c_srcipl);
DDX_Control(pDX, IDC_COMBO1, m_sip);
DDX_Control(pDX, IDC_EDIT4, m_size);
DDX_Control(pDX, IDC_END_TIME, m_timeEnd);
DDX_Control(pDX, IDC_END_DATE, m_dateEnd);
DDX_Control(pDX, IDC_START_DATE, m_dateStart);
DDX_Control(pDX, IDC_START_TIME, m_timeStart);
DDX_Control(pDX, IDC_COMBO5, m_protocol);
DDX_Control(pDX, IDC_IPADDRESS4, m_dstiph);
DDX_Control(pDX, IDC_IPADDRESS3, m_dstipl);
DDX_Control(pDX, IDC_IPADDRESS2, m_srciph);
DDX_Control(pDX, IDC_IPADDRESS1, m_srcipl);
DDX_Text(pDX, IDC_EDIT4, m_length);
DDV_MinMaxUInt(pDX, m_length, 0, 65535);
DDX_DateTimeCtrl(pDX, IDC_END_DATE, m_endDate);
DDX_DateTimeCtrl(pDX, IDC_END_TIME, m_endTime);
DDX_DateTimeCtrl(pDX, IDC_START_DATE, m_startDate);
DDX_DateTimeCtrl(pDX, IDC_START_TIME, m_startTime);
DDX_Check(pDX, IDC_CHECK1, m_start);
DDX_Check(pDX, IDC_CHECK2, m_end);
DDX_Check(pDX, IDC_CHECK3, m_proto);
DDX_Check(pDX, IDC_CHECK4, m_len);
DDX_Check(pDX, IDC_CHECK5, m_b_srcip);
DDX_Check(pDX, IDC_CHECK6, m_b_srcipl);
DDX_Check(pDX, IDC_CHECK7, m_b_srciph);
DDX_Check(pDX, IDC_CHECK9, m_b_dstipl);
DDX_Check(pDX, IDC_CHECK8, m_b_dstip);
DDX_Check(pDX, IDC_CHECK10, m_b_dstiph);
DDX_Check(pDX, IDC_CHECK11, m_b_srcport);
DDX_Check(pDX, IDC_CHECK12, m_b_srcportl);
DDX_Check(pDX, IDC_CHECK13, m_b_srcporth);
DDX_Check(pDX, IDC_CHECK14, m_b_dstport);
DDX_Check(pDX, IDC_CHECK15, m_b_dstportl);
DDX_Check(pDX, IDC_CHECK16, m_b_dstporth);
DDX_Text(pDX, IDC_EDIT6, m_v_dstportl);
DDV_MinMaxUInt(pDX, m_v_dstportl, 0, 65535);
DDX_Text(pDX, IDC_EDIT7, m_v_dstporth);
DDV_MinMaxUInt(pDX, m_v_dstporth, 0, 65535);
DDX_Text(pDX, IDC_EDIT8, m_v_dstport);
DDV_MinMaxUInt(pDX, m_v_dstport, 0, 65535);
DDX_Text(pDX, IDC_EDIT1, m_v_srcportl);
DDV_MinMaxUInt(pDX, m_v_srcportl, 0, 65535);
DDX_Text(pDX, IDC_EDIT2, m_v_srcporth);
DDV_MinMaxUInt(pDX, m_v_srcporth, 0, 65535);
DDX_Text(pDX, IDC_EDIT3, m_v_srcport);
DDV_MinMaxUInt(pDX, m_v_srcport, 0, 65535);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(Filter, CDialog)
//{{AFX_MSG_MAP(Filter)
ON_WM_CANCELMODE()
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_CHECK1, OnStart)
ON_BN_CLICKED(IDC_CHECK2, OnEnd)
ON_BN_CLICKED(IDC_CHECK3, On_proto_check)
ON_BN_CLICKED(IDC_CHECK4, On_len_check)
ON_BN_CLICKED(IDC_CHECK5, On_sip_check)
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1_sip)
ON_BN_CLICKED(IDC_CHECK8, On_dip_check)
ON_CBN_SELCHANGE(IDC_COMBO2, OnSelchangeCombo2_dip)
ON_BN_CLICKED(IDC_CHECK11, On_srcport_check)
ON_CBN_SELCHANGE(IDC_COMBO3, OnSelchangeCombo3_sport)
ON_BN_CLICKED(IDC_CHECK14, On_dstport_check)
ON_CBN_SELCHANGE(IDC_COMBO4, OnSelchangeCombo4_dport)
ON_BN_CLICKED(IDC_CHECK6, On_srcipl_check)
ON_BN_CLICKED(IDC_CHECK7, On_srciph_check)
ON_BN_CLICKED(IDC_CHECK9, On_dstipl_check)
ON_BN_CLICKED(IDC_CHECK10, On_dstiph_check)
ON_BN_CLICKED(IDC_CHECK12, On_srcportl_check)
ON_BN_CLICKED(IDC_CHECK13, On_srcporth_check)
ON_BN_CLICKED(IDC_CHECK15, On_dstportl_check)
ON_BN_CLICKED(IDC_CHECK16, On_dstporth_check)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Filter message handlers
BOOL Filter::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
fnew = false;
fold = false;
m_srcipl.EnableWindow(false);
m_srciph.EnableWindow(false);
m_v_srcip.EnableWindow(false);
m_dstipl.EnableWindow(false);
m_dstiph.EnableWindow(false);
m_v_dstip.EnableWindow(false);
/*this->m_protocol.AddString("TCP");
this->m_protocol.AddString("UDP");
this->m_protocol.AddString("any");*/
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void Filter::OnCancelMode()
{
CDialog::OnCancelMode();
// TODO: Add your message handler code here
}
void Filter::OnRadio1()
{
// TODO: Add your control notification handler code here
fold = true;
fnew = false;
}
void Filter::OnRadio2()
{
// TODO: Add your control notification handler code here
fold = false;
fnew = true;
}
void Filter::OnOK()
{
// TODO: Add extra validation here
CString str = "# ";
CString protocol;
CString srcip,srcipl,srciph,dstip,dstipl,dstiph;
CString srcport,srcportl,srcporth,dstport,dstportl,dstporth;
CString len,DTstart,DTend;
if(!UpdateData()) //check the validity of input
return;
//协议过滤
if(m_proto)
{
m_protocol.GetLBText(m_protocol.GetCurSel(),protocol);
str += protocol + " ";
}
else
str += "any ";
//源IP处理
unsigned char* pIP;
DWORD dwIP;
if(m_b_srcip)
{
if(m_sip.GetCurSel() == 1)
{
m_v_srcip.GetAddress(dwIP);
pIP = (unsigned char*)&dwIP;
srcip.Format("%u.%u.%u.%u",*(pIP+3),*(pIP+2),*(pIP+1),*pIP);
str += srcip + " ";
}
else
{
if(m_b_srcipl)
{
m_srcipl.GetAddress(dwIP);
pIP = (unsigned char*)&dwIP;
srcipl.Format("%u.%u.%u.%u",*(pIP+3),*(pIP+2),*(pIP+1),*pIP);
}
if(m_b_srciph)
{
m_srciph.GetAddress(dwIP);
pIP = (unsigned char*)&dwIP;
srciph.Format("%u.%u.%u.%u",*(pIP+3),*(pIP+2),*(pIP+1),*pIP);
}
if(!m_b_srcipl && !m_b_srciph)
{
MessageBox("请输入源IP过滤范围!");
return;
}
else if(m_b_srcipl && !m_b_srciph)
{
str += srcipl + ": ";
}
else if(m_b_srciph && !m_b_srcipl)
{
str += ":" + srciph + " ";
}
else
{
if(inet_addr(srciph) < inet_addr(srcipl))
{
MessageBox("源IP下限超过上限");
return;
}
str += srcipl + ":" + srciph + " ";
}
}
}
else
str += "any ";
//源端口的处理
if(m_b_srcport)
{
if(m_sport.GetCurSel() == 1)
{
srcport.Format("%d",m_v_srcport);
str += srcport + " -> ";
}
else
{
if(!m_b_srcportl && !m_b_srcporth)
{
MessageBox("请输入源端口过滤范围!");
return;
}
else if(m_b_srcportl && !m_b_srcporth)
{
srcportl.Format("%d",m_v_srcportl);
str += srcportl + ": -> ";
}
else if(m_b_srcporth && !m_b_srcportl)
{
srcporth.Format("%d",m_v_srcporth);
str += ":" + srcporth + " -> ";
}
else
{
if(m_v_srcportl > m_v_srcporth)
{
AfxMessageBox("源端口下限超过了上限");
return;
}
srcportl.Format("%d",m_v_srcportl);
srcporth.Format("%d",m_v_srcporth);
str += srcportl + ":" + srcporth + " -> ";
}
}
}
else
str += "any -> ";
//目的IP的处理
if(m_b_dstip)
{
if(m_dip.GetCurSel() == 1)
{
m_v_dstip.GetAddress(dwIP);
pIP = (unsigned char*)&dwIP;
dstip.Format("%u.%u.%u.%u",*(pIP+3),*(pIP+2),*(pIP+1),*pIP);
str += dstip + " ";
}
else
{
if(m_b_dstipl)
{
m_dstipl.GetAddress(dwIP);
pIP = (unsigned char*)&dwIP;
dstipl.Format("%u.%u.%u.%u",*(pIP+3),*(pIP+2),*(pIP+1),*pIP);
}
if(m_b_dstiph)
{
m_dstiph.GetAddress(dwIP);
pIP = (unsigned char*)&dwIP;
dstiph.Format("%u.%u.%u.%u",*(pIP+3),*(pIP+2),*(pIP+1),*pIP);
}
if(!m_b_dstipl && !m_b_dstiph)
{
MessageBox("请输入目的IP过滤范围!");
return;
}
else if(m_b_dstipl && !m_b_dstiph)
{
str += dstipl + ": ";
}
else if(m_b_dstiph && !m_b_dstipl)
{
str += ":" + dstiph + " ";
}
else
{
if(inet_addr(dstiph) < inet_addr(dstipl))
{
MessageBox("目的IP下限超过上限");
return;
}
str += dstipl + ":" + dstiph + " ";
}
}
}
else
str += "any ";
//目的端口的处理
if(m_b_dstport)
{
if(m_dport.GetCurSel() == 1)
{
dstport.Format("%d",m_v_dstport);
str += dstport + " ";
}
else
{
if(!m_b_dstportl && !m_b_dstporth)
{
MessageBox("请输入目的端口过滤范围!");
return;
}
else if(m_b_dstportl && !m_b_dstporth)
{
dstportl.Format("%d",m_v_dstportl);
str += dstportl + ": ";
}
else if(m_b_dstporth && !m_b_dstportl)
{
dstporth.Format("%d",m_v_dstporth);
str += ":" + dstporth + " ";
}
else
{
if(m_v_dstportl > m_v_dstporth)
{
AfxMessageBox("目的端口下限超过了上限");
return;
}
dstportl.Format("%d",m_v_dstportl);
dstporth.Format("%d",m_v_dstporth);
str += dstportl + ":" + dstporth + " ";
}
}
}
else
str += "any ";
//可选项(长度、日期时间)的处理
if(m_len || m_start || m_end)
{
str += "(";
if(m_len)
{
len.Format("%d",m_length);
str += "len:" + len +";";
}
if(m_start && m_end)
{
DTstart = m_startDate.Format("%Y-%m-%d") + " " + m_startTime.Format("%H:%M:%S");
DTend = m_endDate.Format("%Y-%m-%d") + " " + m_endTime.Format("%H:%M:%S");
if(DTstart > DTend)
{
MessageBox("时间下限超过了时间上限");
return ;
}
str += "ts:" + DTstart + "~" + DTend + ";) #";
}
else if(!m_start && m_end)
{
DTend = m_endDate.Format("%Y-%m-%d") + " " + m_endTime.Format("%H:%M:%S");
str += "ts:~" + DTend + ";) #";
}
else if(!m_end && m_start)
{
DTstart = m_startDate.Format("%Y-%m-%d") + " " + m_startTime.Format("%H:%M:%S");
str += "ts:" + DTstart + "~;) #";
}
else
{
str += ") #";
}
}
else
str += "#";
//根据操作的选择,进行具体的操作
CString lpszFilter; ///file filter
lpszFilter = "Txt Files (*.txt)|*.txt|";
if(!(fnew || fold))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -