如何将请求从不同的静态IP地址发送到任何网站? [英] How to send request from different static IP address to a any website?

查看:89
本文介绍了如何将请求从不同的静态IP地址发送到任何网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#发送HTTP请求.( http://codesamplez.com/programming/http-request-c-sharp)

I am sending HTTP request using C#. (http://codesamplez.com/programming/http-request-c-sharp)

我已启用专用服务器.我购买了更多静态IP.

I have dedicated server on.I have purchased more static IPs.

如何使用这些不同的IP发送请求.

How can I send request using these different IPs.

推荐答案

您想要做的是绑定到特定的网络适配器.默认情况下,LocalEndpoint为null,因此将为您的连接分配一个适配器.您可以使用HttpWebRequest.ServicePoint.BindIPEndPointDelegate指定要绑定的内容.

What you want to do is bind to a specific network adapter. By default the LocalEndpoint is null so your connection will be to assigned an adapter. You can specify what to bind to using HttpWebRequest.ServicePoint.BindIPEndPointDelegate.

var req = (HttpWebRequest)WebRequest.Create("http://google.com/");
req.ServicePoint.BindIPEndPointDelegate = BindTo;
using (req.GetResponse());

static IPEndPoint BindTo(ServicePoint servicepoint, IPEndPoint remoteendpoint, int retrycount)
{
    IPAddress ip = IPAddress.Any; //This is where you specify the network adapter's address
    int port = 0; //This in most cases should stay 0. This when 0 will bind to any port available.
    return new IPEndPoint(ip, port);
}

此处提供了有关绑定的更多信息msdn.

如果需要使用特定的本地终结点,请使用Bind方法.你必须先调用Bind,然后才能调用Listen方法.您不需要在使用Connect方法之前先调用Bind,除非您需要使用特定的本地端点.无连接和面向连接的协议.

Use the Bind method if you need to use a specific local endpoint. You must call Bind before you can call the Listen method. You do not need to call Bind before using the Connect method unless you need to use a specific local endpoint. You can use the Bind method on both connectionless and connection-oriented protocols.

在调用Bind之前,必须首先从以下位置创建本地IPEndPoint您打算传达的数据.如果您不在乎哪个本地地址已分配,您可以使用IPAddress.Any创建IPEndPoint作为地址参数,基础服务提供商将分配最合适的网络地址.这可能有助于简化您的应用程序(如果您有多个网络接口).如果你这样做不在乎使用哪个本地端口,您可以使用创建一个IPEndPoint端口号为0.在这种情况下,服务提供商将分配可用的端口号,介于1024和5000之间.

如果使用上述方法,则可以发现哪些本地网络地址和端口号已通过调用LocalEndPoint.如果您使用的是面向连接的协议,LocalEndPoint将不返回本地分配的网络地址直到调用Connect或EndConnect方法之后.如果您使用的是无连接协议,则您将无权访问直到您完成发送或接收为止.

If you use the above approach, you can discover what local network address and port number has been assigned by calling the LocalEndPoint. If you are using a connection-oriented protocol, LocalEndPoint will not return the locally assigned network address until after you have made a call to the Connect or EndConnect method. If you are using a connectionless protocol, you will not have access to this information until you have completed a send or receive.

这篇关于如何将请求从不同的静态IP地址发送到任何网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆