Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Generally said, this is not that easy.</p> <p><strong>Detection of Bandwidth</strong></p> <p>The .NET framework provides <a href="http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.aspx" rel="nofollow">classes</a> which give you information about network adapter performance, but as far as I know they only consider the technical specification of the network card itself, not the bandwidth of the connection. However, this may be enough for your purpose. </p> <p>If you want to detect the bandwith of a connection, you not only have to observe the network adapter and it's capabilities, but also the properties of the connection or even the whole infrastructure (the routing or switching hardware, the cables, the amount of traffic, the utilization and much more). There are powerful frameworks, for example nagios, which perform such monitoring. </p> <p>Fore the beginning, you could start with analyzing delays in TCP connections or utilizing ICMP echos (pings) for measurement, but be warned, this is not an easy task. </p> <p><strong>Routing</strong></p> <p>Since you cannot write kernel-mode or driver code in C#, you will have perform "userland" routing, by monitoring the traffic and using a library like WinPcap to send out the network packets to the correct interface. (I assume simply changing the system routes is not enough, since you wrote that you want to route each packet individually). </p> <p>There is already a library, called <a href="http://eex.codeplex.com/" rel="nofollow">eEx Network Library</a>, which provides classes and an infrastructure to accomplish such tasks in C#. There also is an example for <a href="http://network.eex-dev.net/index.php?id=64&amp;tx_drwiki_pi1%5Bkeyword%5D=Your%20first%20Router" rel="nofollow">routing</a>, which you can use as starting point. You can create a custom router by inheriting from the classes Router or DirectInterfaceIO, depending on what suits you best. </p> <p>Here is an example, which can replace the Router class in the example mentioned above. </p> <pre class="lang-cs prettyprint-override"><code>//A simple, custom router public class CustomRouter : DirectInterfaceIOHandler { //Is called for each frame - place your logic here. protected override void HandleTraffic(Frame fInputFrame) { //Get the IP frame //IPv4Frame ipv4frame = GetIPv4Frame(fInputFrame); IPFrame ipframe = GetIPFrame(fInputFrame); if (ipframe != null) { //Iterate over all interfaces. foreach (IPInterface ipInterface in lInterfaces) { //Adjust this condition to check whether ipInterface is the correct interface for this frame if (true) { //With this overload of send, the interface handles hardware addressing. ipInterface.Send(fInputFrame, ipframe.DestinationAddress); } } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload