工控编程吧
标题: 上位机MFC如何获得本地计算机的TCP协议统计信息 [打印本页]
作者: qq263946146 时间: 2019-8-8 10:43
标题: 上位机MFC如何获得本地计算机的TCP协议统计信息
- #include "IPHlpApi.h"
- #pragma comment(lib,"IPHLPAPI.LIB")
- #pragma comment(lib,"netapi32.lib ")
- void CGkbc8Dlg::OnButton2()
- {
- CListBox* pListBox = (CListBox*)GetDlgItem(IDC_LIST1);
- pListBox->ResetContent();
- MIB_TCPSTATS TCPStats;
- //获得TCP协议统计信息
- if (GetTcpStatistics(&TCPStats) != NO_ERROR)
- {
- return;
- }
- CString strText = _T("");
- strText.Format(_T("time-out algorithm:%d"),
- TCPStats.dwRtoAlgorithm);
- pListBox->AddString(strText);
- strText.Format(_T("minimum time-out:%d"),
- TCPStats.dwRtoMin);
- pListBox->AddString(strText);
- strText.Format(_T("maximum time-out:%d"),
- TCPStats.dwRtoMax);
- pListBox->AddString(strText);
- strText.Format(_T("maximum connections:%d"),
- TCPStats.dwMaxConn);
- pListBox->AddString(strText);
- strText.Format(_T("active opens:%d"),
- TCPStats.dwActiveOpens);
- pListBox->AddString(strText);
- strText.Format(_T("passive opens:%d"),
- TCPStats.dwPassiveOpens);
- pListBox->AddString(strText);
- strText.Format(_T("failed attempts:%d"),
- TCPStats.dwAttemptFails);
- pListBox->AddString(strText);
- strText.Format(_T("established connections reset:%d"),
- TCPStats.dwEstabResets);
- pListBox->AddString(strText);
- strText.Format(_T("established connections:%d"),
- TCPStats.dwCurrEstab);
- pListBox->AddString(strText);
- strText.Format(_T("segments received:%d"),
- TCPStats.dwInSegs);
- pListBox->AddString(strText);
- strText.Format(_T("segment sent:%d"),
- TCPStats.dwOutSegs);
- pListBox->AddString(strText);
- strText.Format(_T("segments retransmitted:%d"),
- TCPStats.dwRetransSegs);
- pListBox->AddString(strText);
- strText.Format(_T("incoming errors:%d"),
- TCPStats.dwInErrs);
- pListBox->AddString(strText);
- strText.Format(_T("outgoing resets:%d"),
- TCPStats.dwOutRsts);
- pListBox->AddString(strText);
- strText.Format(_T("cumulative connections:%d"),
- TCPStats.dwNumConns);
- pListBox->AddString(strText);
- }
复制代码
如上面的按钮点击代码。点击后会在列表控件中显示出信息。
IDC_LIST1为我们添加的列表框控件ID:CListBox;
(, 下载次数: 1)