<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Netzwerktraffic mit Win32_PerfFormattedData_Tcpip_NetworkInterface auslesen?]]></title><description><![CDATA[<p>Mojn zusammen!</p>
<p>Ich bin gerade ein bisschen am basteln!</p>
<p>Ich möchte meinen Traffic auslesen ...</p>
<p>Ich hab schon gelesen das dies mit TDI-Filtern gehen soll, hab aber auf die schnelle nix brauchbares gefunden ...</p>
<p>Dann hab ich in der WMI das gefunden:</p>
<pre><code class="language-cpp">class Win32_PerfFormattedData_Tcpip_NetworkInterface : Win32_PerfFormattedData
{
  uint32 BytesReceivedPerSec;
  uint32 BytesSentPerSec;
  uint64 BytesTotalPerSec;
  string Caption;
  uint32 CurrentBandwidth;
  string Description;
  uint64 Frequency_Object;
  uint64 Frequency_PerfTime;
  uint64 Frequency_Sys100NS;
  string Name;
  uint32 OutputQueueLength;
  uint32 PacketsOutboundDiscarded;
  uint32 PacketsOutboundErrors;
  uint32 PacketsPerSec;
  uint32 PacketsReceivedDiscarded;
  uint32 PacketsReceivedErrors;
  uint32 PacketsReceivedNonUnicastPerSec;
  uint32 PacketsReceivedPerSec;
  uint32 PacketsReceivedUnicastPerSec;
  uint32 PacketsReceivedUnknown;
  uint32 PacketsSentNonUnicastPerSec;
  uint32 PacketsSentPerSec;
  uint32 PacketsSentUnicastPerSec;
  uint64 Timestamp_Object;
  uint64 Timestamp_PerfTime;
  uint64 Timestamp_Sys100NS;
};
</code></pre>
<p>So schön und gut!</p>
<p>Ich kann das ganze auch abfragen, nur mit einem kleinen Problem, es sieht wohl so aus, als würden die Daten nur einmal pro Sekunde gefüllt werden, und danach steht überall 0 drin, wenn man jetzt nicht zufällig den richtigen Zeitpunkt erwischt, erhaltet man 0 BytesReceivedBySec, obwohl man gerade mit voller last zieht ....</p>
<p>Weiß jmd ne lösung dafür??</p>
<p>Hier mal mein Quellcode der die Daten ausliest:</p>
<pre><code class="language-cpp">int NEOsLcdClass::InitializeWMI()
{
	//Just set to true if Initialation was Successfull
	InitializedWbem = false;

	HRESULT result;

	pLoc = NULL;
	pSvc = NULL;

	SYSTEM_INFO SysInfo;
	GetSystemInfo(&amp;SysInfo);
	NumberOfProzessors = SysInfo.dwNumberOfProcessors;

	if(NumberOfProzessors &gt; 1)
		NumberOfProzessors ++;

	result = CoInitializeEx(0, COINIT_MULTITHREADED);

	if(result != S_OK)
	{
		/* Initializing Failed! */
		return 1;
	}

	/* Set COM security levels */
	result = CoInitializeSecurity(
			NULL, 
			-1,                          // COM authentication
			NULL,                        // Authentication services
			NULL,                        // Reserved
			RPC_C_AUTHN_LEVEL_DEFAULT,   // Default authentication 
			RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation  
			NULL,                        // Authentication info
			EOAC_NONE,                   // Additional capabilities 
			NULL                         // Reserved
			);
	if(result != S_OK)
	{
		/* Failed! */
		return 1;
	}

	/* Obtain the initial locator to WMI */
	result = CoCreateInstance(CLSID_WbemLocator,0,CLSCTX_INPROC_SERVER,IID_IWbemLocator, (LPVOID *) &amp;pLoc);

	if(result != S_OK)
	{
		/* Failed! */
		return 1;
	}

	/* Connect to WMI through the IWbemLocator::ConnectServer method */
	result = pLoc-&gt;ConnectServer(
		_T(&quot;ROOT\\CIMV2&quot;), // Object path of WMI namespace
		NULL,                    // User name. NULL = current user
		NULL,                    // User password. NULL = current
		0,                       // Locale. NULL indicates current
		NULL,                    // Security flags.
		0,                       // Authority (e.g. Kerberos)
		0,                       // Context object 
		&amp;pSvc                    // pointer to IWbemServices proxy
		);
	if(result != WBEM_S_NO_ERROR)
	{
		/* Failed! */
		return 1;
	}

	/* Set security levels on the proxy */
	result = CoSetProxyBlanket(
			pSvc,                        // Indicates the proxy to set
			RPC_C_AUTHN_WINNT,           // RPC_C_AUTHN_xxx
			RPC_C_AUTHZ_NONE,            // RPC_C_AUTHZ_xxx
			NULL,                        // Server principal name 
			RPC_C_AUTHN_LEVEL_CALL,      // RPC_C_AUTHN_LEVEL_xxx 
			RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
			NULL,                        // client identity
			EOAC_NONE                    // proxy capabilities 
		);
	if(result != S_OK)
	{
		/* Failed! */
		return 1;
	}
	InitializedWbem = true;

	return 0;
}

vector&lt;int&gt; NEOsLcdClass::GetNetUsages(vector &lt;CString&gt; &amp;Interfaces)
{
	vector&lt;int&gt; Usages;

/* BEGIN */

	HRESULT result;
	IEnumWbemClassObject* pEnumerator = NULL;
	IWbemClassObject *pclsObj;
	DWORD uReturn;

	Interfaces.clear();

	if(InitializedWbem)
	{
		/* Use the IWbemServices pointer to make requests of WMI */

		result = pSvc-&gt;ExecQuery(
					_T(&quot;WQL&quot;), 
					_T(&quot;SELECT * FROM Win32_PerfFormattedData_Tcpip_NetworkInterface&quot;),

					WBEM_FLAG_BIDIRECTIONAL, 
					NULL,
					&amp;pEnumerator);

		if(/*result != WBEM_S_NO_ERROR*/FAILED(result))
		{
			/* Failed! */
			AfxMessageBox(L&quot;Something Happend :(&quot; + IntToStr(WBEM_S_NO_ERROR));
			vector&lt;int&gt; ClearRetVal;
			return ClearRetVal;
		}

		/* Get data */

		int i = 0;

		while(true)
		{
			VARIANT vtProp;

			result = pEnumerator-&gt;Next(WBEM_INFINITE, 1, &amp;pclsObj, &amp;uReturn);

			if(uReturn != 0 )
			{

				VariantInit(&amp;vtProp);

				//swscanf(vtProp.bstrVal, L&quot;%I64u&quot;, &amp;ulVal[nCtr]);

				Usages.resize(Usages.size()+1);

				result = pclsObj-&gt;Get(L&quot;BytesReceivedPerSec&quot;, 0, &amp;vtProp, 0, 0);
				Usages[Usages.size()-1] = vtProp.lVal;
				VariantClear(&amp;vtProp);

				Usages.resize(Usages.size()+1);
				result = pclsObj-&gt;Get(L&quot;BytesSentPerSec&quot;, 0, &amp;vtProp, 0, 0);
				Usages[Usages.size()-1] = vtProp.lVal;
				VariantClear(&amp;vtProp);

				Usages.resize(Usages.size()+1);
				result = pclsObj-&gt;Get(L&quot;CurrentBandwidth&quot;, 0, &amp;vtProp, 0, 0);
				Usages[Usages.size()-1] = vtProp.lVal;
				VariantClear(&amp;vtProp);

				Interfaces.resize(Interfaces.size()+1);
				result = pclsObj-&gt;Get(L&quot;Name&quot;, 0, &amp;vtProp, 0, 0);
				Interfaces[Interfaces.size()-1] = vtProp.bstrVal;
				VariantClear(&amp;vtProp);

				//AfxMessageBox(IntToStr(vtProp.vt));

				//AfxMessageBox(tmpStr);

//				swscanf(vtProp.bstrVal,L&quot;%d&quot;,&amp;Usages[Usages.size()-1]);
				VariantClear(&amp;vtProp);

				//VERY IMPORTANT!! OTHERWISE MEMORY INCREASES!!
				pclsObj-&gt;Release();
			}
			else
			{
				// Ups? 
				break;
			}
		}

	}
	pEnumerator-&gt;Release();

	return Usages;
}
</code></pre>
<p>Die Methode GetNetUsages wird übern Timer ca. alle 50 ms aufgerufen!</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/165908/netzwerktraffic-mit-win32_perfformatteddata_tcpip_networkinterface-auslesen</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Jul 2026 01:49:53 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/165908.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 24 Nov 2006 07:19:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Netzwerktraffic mit Win32_PerfFormattedData_Tcpip_NetworkInterface auslesen? on Fri, 24 Nov 2006 07:19:10 GMT]]></title><description><![CDATA[<p>Mojn zusammen!</p>
<p>Ich bin gerade ein bisschen am basteln!</p>
<p>Ich möchte meinen Traffic auslesen ...</p>
<p>Ich hab schon gelesen das dies mit TDI-Filtern gehen soll, hab aber auf die schnelle nix brauchbares gefunden ...</p>
<p>Dann hab ich in der WMI das gefunden:</p>
<pre><code class="language-cpp">class Win32_PerfFormattedData_Tcpip_NetworkInterface : Win32_PerfFormattedData
{
  uint32 BytesReceivedPerSec;
  uint32 BytesSentPerSec;
  uint64 BytesTotalPerSec;
  string Caption;
  uint32 CurrentBandwidth;
  string Description;
  uint64 Frequency_Object;
  uint64 Frequency_PerfTime;
  uint64 Frequency_Sys100NS;
  string Name;
  uint32 OutputQueueLength;
  uint32 PacketsOutboundDiscarded;
  uint32 PacketsOutboundErrors;
  uint32 PacketsPerSec;
  uint32 PacketsReceivedDiscarded;
  uint32 PacketsReceivedErrors;
  uint32 PacketsReceivedNonUnicastPerSec;
  uint32 PacketsReceivedPerSec;
  uint32 PacketsReceivedUnicastPerSec;
  uint32 PacketsReceivedUnknown;
  uint32 PacketsSentNonUnicastPerSec;
  uint32 PacketsSentPerSec;
  uint32 PacketsSentUnicastPerSec;
  uint64 Timestamp_Object;
  uint64 Timestamp_PerfTime;
  uint64 Timestamp_Sys100NS;
};
</code></pre>
<p>So schön und gut!</p>
<p>Ich kann das ganze auch abfragen, nur mit einem kleinen Problem, es sieht wohl so aus, als würden die Daten nur einmal pro Sekunde gefüllt werden, und danach steht überall 0 drin, wenn man jetzt nicht zufällig den richtigen Zeitpunkt erwischt, erhaltet man 0 BytesReceivedBySec, obwohl man gerade mit voller last zieht ....</p>
<p>Weiß jmd ne lösung dafür??</p>
<p>Hier mal mein Quellcode der die Daten ausliest:</p>
<pre><code class="language-cpp">int NEOsLcdClass::InitializeWMI()
{
	//Just set to true if Initialation was Successfull
	InitializedWbem = false;

	HRESULT result;

	pLoc = NULL;
	pSvc = NULL;

	SYSTEM_INFO SysInfo;
	GetSystemInfo(&amp;SysInfo);
	NumberOfProzessors = SysInfo.dwNumberOfProcessors;

	if(NumberOfProzessors &gt; 1)
		NumberOfProzessors ++;

	result = CoInitializeEx(0, COINIT_MULTITHREADED);

	if(result != S_OK)
	{
		/* Initializing Failed! */
		return 1;
	}

	/* Set COM security levels */
	result = CoInitializeSecurity(
			NULL, 
			-1,                          // COM authentication
			NULL,                        // Authentication services
			NULL,                        // Reserved
			RPC_C_AUTHN_LEVEL_DEFAULT,   // Default authentication 
			RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation  
			NULL,                        // Authentication info
			EOAC_NONE,                   // Additional capabilities 
			NULL                         // Reserved
			);
	if(result != S_OK)
	{
		/* Failed! */
		return 1;
	}

	/* Obtain the initial locator to WMI */
	result = CoCreateInstance(CLSID_WbemLocator,0,CLSCTX_INPROC_SERVER,IID_IWbemLocator, (LPVOID *) &amp;pLoc);

	if(result != S_OK)
	{
		/* Failed! */
		return 1;
	}

	/* Connect to WMI through the IWbemLocator::ConnectServer method */
	result = pLoc-&gt;ConnectServer(
		_T(&quot;ROOT\\CIMV2&quot;), // Object path of WMI namespace
		NULL,                    // User name. NULL = current user
		NULL,                    // User password. NULL = current
		0,                       // Locale. NULL indicates current
		NULL,                    // Security flags.
		0,                       // Authority (e.g. Kerberos)
		0,                       // Context object 
		&amp;pSvc                    // pointer to IWbemServices proxy
		);
	if(result != WBEM_S_NO_ERROR)
	{
		/* Failed! */
		return 1;
	}

	/* Set security levels on the proxy */
	result = CoSetProxyBlanket(
			pSvc,                        // Indicates the proxy to set
			RPC_C_AUTHN_WINNT,           // RPC_C_AUTHN_xxx
			RPC_C_AUTHZ_NONE,            // RPC_C_AUTHZ_xxx
			NULL,                        // Server principal name 
			RPC_C_AUTHN_LEVEL_CALL,      // RPC_C_AUTHN_LEVEL_xxx 
			RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
			NULL,                        // client identity
			EOAC_NONE                    // proxy capabilities 
		);
	if(result != S_OK)
	{
		/* Failed! */
		return 1;
	}
	InitializedWbem = true;

	return 0;
}

vector&lt;int&gt; NEOsLcdClass::GetNetUsages(vector &lt;CString&gt; &amp;Interfaces)
{
	vector&lt;int&gt; Usages;

/* BEGIN */

	HRESULT result;
	IEnumWbemClassObject* pEnumerator = NULL;
	IWbemClassObject *pclsObj;
	DWORD uReturn;

	Interfaces.clear();

	if(InitializedWbem)
	{
		/* Use the IWbemServices pointer to make requests of WMI */

		result = pSvc-&gt;ExecQuery(
					_T(&quot;WQL&quot;), 
					_T(&quot;SELECT * FROM Win32_PerfFormattedData_Tcpip_NetworkInterface&quot;),

					WBEM_FLAG_BIDIRECTIONAL, 
					NULL,
					&amp;pEnumerator);

		if(/*result != WBEM_S_NO_ERROR*/FAILED(result))
		{
			/* Failed! */
			AfxMessageBox(L&quot;Something Happend :(&quot; + IntToStr(WBEM_S_NO_ERROR));
			vector&lt;int&gt; ClearRetVal;
			return ClearRetVal;
		}

		/* Get data */

		int i = 0;

		while(true)
		{
			VARIANT vtProp;

			result = pEnumerator-&gt;Next(WBEM_INFINITE, 1, &amp;pclsObj, &amp;uReturn);

			if(uReturn != 0 )
			{

				VariantInit(&amp;vtProp);

				//swscanf(vtProp.bstrVal, L&quot;%I64u&quot;, &amp;ulVal[nCtr]);

				Usages.resize(Usages.size()+1);

				result = pclsObj-&gt;Get(L&quot;BytesReceivedPerSec&quot;, 0, &amp;vtProp, 0, 0);
				Usages[Usages.size()-1] = vtProp.lVal;
				VariantClear(&amp;vtProp);

				Usages.resize(Usages.size()+1);
				result = pclsObj-&gt;Get(L&quot;BytesSentPerSec&quot;, 0, &amp;vtProp, 0, 0);
				Usages[Usages.size()-1] = vtProp.lVal;
				VariantClear(&amp;vtProp);

				Usages.resize(Usages.size()+1);
				result = pclsObj-&gt;Get(L&quot;CurrentBandwidth&quot;, 0, &amp;vtProp, 0, 0);
				Usages[Usages.size()-1] = vtProp.lVal;
				VariantClear(&amp;vtProp);

				Interfaces.resize(Interfaces.size()+1);
				result = pclsObj-&gt;Get(L&quot;Name&quot;, 0, &amp;vtProp, 0, 0);
				Interfaces[Interfaces.size()-1] = vtProp.bstrVal;
				VariantClear(&amp;vtProp);

				//AfxMessageBox(IntToStr(vtProp.vt));

				//AfxMessageBox(tmpStr);

//				swscanf(vtProp.bstrVal,L&quot;%d&quot;,&amp;Usages[Usages.size()-1]);
				VariantClear(&amp;vtProp);

				//VERY IMPORTANT!! OTHERWISE MEMORY INCREASES!!
				pclsObj-&gt;Release();
			}
			else
			{
				// Ups? 
				break;
			}
		}

	}
	pEnumerator-&gt;Release();

	return Usages;
}
</code></pre>
<p>Die Methode GetNetUsages wird übern Timer ca. alle 50 ms aufgerufen!</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1180461</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1180461</guid><dc:creator><![CDATA[pmneo]]></dc:creator><pubDate>Fri, 24 Nov 2006 07:19:10 GMT</pubDate></item><item><title><![CDATA[Reply to Netzwerktraffic mit Win32_PerfFormattedData_Tcpip_NetworkInterface auslesen? on Fri, 24 Nov 2006 22:55:37 GMT]]></title><description><![CDATA[<p>Okay, mit Win32_PerfRawData_Tcpip_NetworkInterface gehts, dort werden die values nicht gelöscht!</p>
<p>Man muss nur noch eine Diferenz errechnen, und die zeit dazwischen dann hat man die up und down raten!</p>
<pre><code class="language-cpp">vector&lt;__int64&gt; NEOsLcdClass::GetNetUsages(vector &lt;CString&gt; &amp;Interfaces)
{
	vector&lt;__int64&gt; Usages;

/* BEGIN */

	HRESULT result;
	IEnumWbemClassObject* pEnumerator = NULL;
	IWbemClassObject *pclsObj;
	DWORD uReturn;

	Interfaces.clear();

	if(InitializedWbem)
	{
		/* Use the IWbemServices pointer to make requests of WMI */

		result = pSvc-&gt;ExecQuery(
					_T(&quot;WQL&quot;), 
					_T(&quot;SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface&quot;),

					WBEM_FLAG_BIDIRECTIONAL, 
					NULL,
					&amp;pEnumerator);

		if(/*result != WBEM_S_NO_ERROR*/FAILED(result))
		{
			/* Failed! */
			AfxMessageBox(L&quot;Something Happend :(&quot; + IntToStr(WBEM_S_NO_ERROR));
			vector&lt;__int64&gt; ClearRetVal;
			return ClearRetVal;
		}

		/* Get data */

		__int64 tmpval;
		int i = 0;
		while(i++ &lt; NumberOfProzessors)
		{
			VARIANT vtProp;

			result = pEnumerator-&gt;Next(WBEM_INFINITE, 1, &amp;pclsObj, &amp;uReturn);

			if(uReturn != 0 )
			{

				VariantInit(&amp;vtProp);

				//swscanf(vtProp.bstrVal, L&quot;%I64u&quot;, &amp;ulVal[nCtr]);
				result = pclsObj-&gt;Get(L&quot;Name&quot;, 0, &amp;vtProp, 0, 0);

				Interfaces.push_back(vtProp.bstrVal);

				//swscanf(vtProp.bstrVal,L&quot;%d&quot;,&amp;Usages[Usages.size()-1]);
				VariantClear(&amp;vtProp);

				result = pclsObj-&gt;Get(L&quot;BytesReceivedPerSec&quot;, 0, &amp;vtProp, 0, 0);
				Usages.push_back(vtProp.ullVal);
				VariantClear(&amp;vtProp);

				result = pclsObj-&gt;Get(L&quot;BytesSentPerSec&quot;, 0, &amp;vtProp, 0, 0);
				Usages.push_back(vtProp.ullVal);
				VariantClear(&amp;vtProp);

				result = pclsObj-&gt;Get(L&quot;Timestamp_Sys100NS&quot;, 0, &amp;vtProp, 0, 0);
				swscanf_s(vtProp.bstrVal, L&quot;%I64u&quot;, &amp;tmpval);
				Usages.push_back(tmpval);

				//Usages.push_back(vtProp.ullVal);
				VariantClear(&amp;vtProp);

				//VERY IMPORTANT!! OTHERWISE MEMORY INCREASES!!
				pclsObj-&gt;Release();
			}
			else
			{
				/* Ups? */
			}
		}		
	}
	pEnumerator-&gt;Release();

	return Usages;
}

void NEOsLcdClass::UpdateUsagesTimerFunction()
{	
	vector&lt;__int64&gt; NetUsage;

	/* GET NET STATS */
	NetUsage = GetNetUsages(NetInterfaces);
	if(NetInterfaces.size() != TotalBytesReceived.size())
	{
		//RESET!!;

		TotalBytesReceived.resize(NetInterfaces.size());
		TotalBytesSent.resize(NetInterfaces.size());
		TimeStamp_Sys100NS.resize(NetInterfaces.size());

		l_TotalBytesReceived.resize(NetInterfaces.size());
		l_TotalBytesSent.resize(NetInterfaces.size());
		l_TimeStamp_Sys100NS.resize(NetInterfaces.size());

		for(int i=0;i&lt;(int)NetInterfaces.size();i++)
		{
			TotalBytesReceived[i] = NetUsage[i*3 + 0];
			TotalBytesSent[i] = NetUsage[i*3 + 1];
			TimeStamp_Sys100NS[i] = NetUsage[i*3 + 2];

			l_TotalBytesReceived[i] = TotalBytesReceived[i];
			l_TotalBytesSent[i] = TotalBytesSent[i];
			l_TimeStamp_Sys100NS[i] = TimeStamp_Sys100NS[i];
		}
	}

	for(i=0;i &lt; NetInterfaces.size(); i++)
	{
		TotalBytesReceived[i] = NetUsage[i*3 + 0];
		TotalBytesSent[i] = NetUsage[i*3 + 1];
		TimeStamp_Sys100NS[i] = NetUsage[i*3 + 2];
	}

	tmpVal = &quot;&quot;;

	__int64 BytesReceived,BytesSent,TimeDif;

	for(i=0;i &lt; TotalBytesReceived.size(); i++)
	{
		BytesReceived = TotalBytesReceived[i] - l_TotalBytesReceived[i];
		BytesSent = TotalBytesSent[i] - l_TotalBytesSent[i];

		TimeDif = TimeStamp_Sys100NS[i] - l_TimeStamp_Sys100NS[i];

		if(TimeDif &gt; 0)
		{
			BytesReceived = (int)floor((double)10000000/TimeDif * BytesReceived);
			BytesSent = (int)floor((double)10000000/TimeDif * BytesSent);
		}
		else
		{
			BytesReceived = 0;
			BytesSent = 0;
		}
//Reset Vals
		l_TotalBytesReceived[i] = TotalBytesReceived[i];
		l_TotalBytesSent[i] = TotalBytesSent[i];
		l_TimeStamp_Sys100NS[i] = TimeStamp_Sys100NS[i];

	}
}
</code></pre>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1181005</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1181005</guid><dc:creator><![CDATA[pmneo]]></dc:creator><pubDate>Fri, 24 Nov 2006 22:55:37 GMT</pubDate></item></channel></rss>