工控编程吧
标题:
上位机MFC网络抓包程序源代码
[打印本页]
作者:
qq263946146
时间:
2019-9-5 09:59
标题:
上位机MFC网络抓包程序源代码
(, 下载次数: 1)
上传
点击文件名下载附件
(, 下载次数: 0)
上传
点击文件名下载附件
如上图,点击开始可以进网络数据抓包。
调用的按钮函数为
void CIPPackageDlg::OnBstart()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_BSTART)->EnableWindow(false);
GetDlgItem(IDC_BPAUSE)->EnableWindow(true);
pThread=AfxBeginThread(&WorkThread,0);
}
复制代码
线程函数为
UINT WorkThread(LPVOID lpParam)
{
CIPPackageDlg *dlg = (CIPPackageDlg*)AfxGetApp()->GetMainWnd();
CString str;
int nCount;
while (TRUE)
{
//接收原始数据包信息
int ret = recv(dlg->Socket, dlg->RecvBuf, 65535, 0);
nCount = dlg->m_ctrList.GetItemCount();
if (ret > 0)
{
dlg->ip = *(IP*)dlg->RecvBuf;
dlg->tcp = *(TCP*)(dlg->RecvBuf + dlg->ip.HdrLen);
str.Format("%s",dlg->GetProtocolTxt(dlg->ip.Protocol));
dlg->m_ctrList.InsertItem(0, str);
str.Format(" %-15s",inet_ntoa(*(in_addr*)&dlg->ip.SrcAddr));
dlg->m_ctrList.SetItemText(0, 1, str);
str.Format(" %-15s",inet_ntoa(*(in_addr*)&dlg->ip.DstAddr));
dlg->m_ctrList.SetItemText(0, 2, str);
str.Format(" %-5d",dlg->tcp.SrcPort);
dlg->m_ctrList.SetItemText(0, 3, str);
str.Format("%-5d",dlg->tcp.DstPort);
dlg->m_ctrList.SetItemText(0, 4, str);
str.Format(" %-4d",ntohs(dlg->ip.TotalLen));
dlg->m_ctrList.SetItemText(0, 5, str);
}
}
return 1;
}
复制代码
更多可以下载源代码学习。
欢迎光临 工控编程吧 (https://www.gkbc8.com/)
Powered by Discuz! X3.4