Daily using/supporting

Get Firefox browser!
Get Thunderbird!
Get Opera browser!
Get The Gimp!
Get Inkscape!
Get LibreOffice!
Get Videolan!
Get Linux!
Get Mandriva!
Get Joomla!
Hacker Emblem

Archives

Which topics would you like us to cover more?

Latest comments

Home Architecture, security and coding Force the use of a networking adapter using C#
Force the use of a networking adapter using C#
Written by Division by Zero   
Thursday, 12 April 2012 11:03

A while ago I described a problem I had with PHP. I had the same problem using C#. Here's how to force the use of a networking adapter using C#.

// Create a request to a specific url
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.test.com");
// Add an endPointDelegate
request.ServicePoint.BindIPEndPointDelegate = new BindIPEndPoint(BindIPEndPointCallback);
// Execute the request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
 
// Here's the code of the delegate
private IPEndPoint BindIPEndPointCallback(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount)
{
    // Fill the byte array with the desired IP-address to force the outgoing request to go to that device
    return new IPEndPoint(new IPAddress(new byte[]{xx,xx,xx,xx}), 0);
}
Tags:
 

Add comment


Security code
Refresh

I think, therefore I am. - R. Descartes


© 2009 - 2013, Division by Zero

Template based on the empire template by joomlashack 

 Creative Commons License
This work by Division by Zero is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Netherlands License.