工控编程吧
标题: 上位机MFC如何获得本地计算机的IP协议统计信息 [打印本页]
作者: qq263946146 时间: 2019-8-8 10:47
标题: 上位机MFC如何获得本地计算机的IP协议统计信息
- #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_IPSTATS IPStats;
- //获得IP协议统计信息
- if (GetIpStatistics(&IPStats) != NO_ERROR)
- {
- return;
- }
- CString strText = _T("");
- strText.Format(_T("IP forwarding enabled or disabled:%d"),
- IPStats.dwForwarding);
- pListBox->AddString(strText);
- strText.Format(_T("default time-to-live:%d"),
- IPStats.dwDefaultTTL);
- pListBox->AddString(strText);
- strText.Format(_T("datagrams received:%d"),
- IPStats.dwInReceives);
- pListBox->AddString(strText);
- strText.Format(_T("received header errors:%d"),
- IPStats.dwInHdrErrors);
- pListBox->AddString(strText);
- strText.Format(_T("received address errors:%d"),
- IPStats.dwInAddrErrors);
- pListBox->AddString(strText);
- strText.Format(_T("datagrams forwarded:%d"),
- IPStats.dwForwDatagrams);
- pListBox->AddString(strText);
- strText.Format(_T("datagrams with unknown protocol:%d"),
- IPStats.dwInUnknownProtos);
- pListBox->AddString(strText);
- strText.Format(_T("received datagrams discarded:%d"),
- IPStats.dwInDiscards);
- pListBox->AddString(strText);
- strText.Format(_T("received datagrams delivered:%d"),
- IPStats.dwInDelivers);
- pListBox->AddString(strText);
- strText.Format(_T("outgoing datagrams requested to send:%d"),
- IPStats.dwOutRequests);
- pListBox->AddString(strText);
- strText.Format(_T("outgoing datagrams discarded:%d"),
- IPStats.dwOutDiscards);
- pListBox->AddString(strText);
- strText.Format(_T("sent datagrams discarded:%d"),
- IPStats.dwOutDiscards);
- pListBox->AddString(strText);
- strText.Format(_T("datagrams for which no route exists:%d"),
- IPStats.dwOutNoRoutes);
- pListBox->AddString(strText);
- strText.Format(_T("datagrams for which all frags did not arrive:%d"),
- IPStats.dwReasmTimeout);
- pListBox->AddString(strText);
- strText.Format(_T("datagrams requiring reassembly:%d"),
- IPStats.dwReasmReqds);
- pListBox->AddString(strText);
- strText.Format(_T("successful reassemblies:%d"),
- IPStats.dwReasmOks);
- pListBox->AddString(strText);
- strText.Format(_T("failed reassemblies:%d"),
- IPStats.dwReasmFails);
- pListBox->AddString(strText);
- strText.Format(_T("successful fragmentations:%d"),
- IPStats.dwFragOks);
- pListBox->AddString(strText);
- strText.Format(_T("failed fragmentations:%d"),
- IPStats.dwFragFails);
- pListBox->AddString(strText);
- strText.Format(_T("datagrams fragmented:%d"),
- IPStats.dwFragCreates);
- pListBox->AddString(strText);
- strText.Format(_T("number of interfaces on computer:%d"),
- IPStats.dwNumIf);
- pListBox->AddString(strText);
- strText.Format(_T("number of IP address on computer:%d"),
- IPStats.dwNumAddr);
- pListBox->AddString(strText);
- strText.Format(_T("number of routes in routing table:%d"),
- IPStats.dwNumRoutes);
- pListBox->AddString(strText);
- }
复制代码 如上代码,在按钮的点击函数内调用,可以显示出相关供。
(, 下载次数: 0)