Skip to content

Instantly share code, notes, and snippets.

@cpoDesign
Created June 1, 2018 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpoDesign/020390bd50c3b31b3f9b4c8def65ca99 to your computer and use it in GitHub Desktop.
Save cpoDesign/020390bd50c3b31b3f9b4c8def65ca99 to your computer and use it in GitHub Desktop.
Force request to specific IP address and port
string sendingIp = "192.168.0.1";
int sendingPort = 5000;
Uri uri = new Uri("http://google.com");
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(uri);
ServicePoint sp = ServicePointManager.FindServicePoint(uri);
sp.BindIPEndPointDelegate =
(servicePoint,remoteEp,retryCount) =>
{
return new IPEndPoint(IPAddress.Parse(sendingIp),sendingPort);
};
var data = new StreamReader(wr.GetResponse().GetResponseStream()).ReadToEnd();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment