static void Main(string[] args)
{
//ssl证书验证问题(没有校验)
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
var hostname = Dns.GetHostName();//获取本地主机名
var addresses = Dns.GetHostAddresses(hostname);//返回指定主机的 Internet 协议 (IP) 地址
foreach (var address in addresses)
{
if (address.AddressFamily != System.Net.Sockets.AddressFamily.InterNetwork) continue;//version 4.0
Console.WriteLine(address);
var client = new MyWebClient(address);
var rlt = client.UploadString("https://t2.ipyy.net/a.aspx", "");
Console.WriteLine(rlt);
Console.WriteLine("----------------------------------");
}
Console.WriteLine("r.ipyy.net");
var ipr = Dns.GetHostAddresses("r.ipyy.net");
var rc = new MyWebClient(ipr.First());
var r = rc.UploadString("https://t2.ipyy.net/a.aspx", "");
Console.WriteLine(r);
Console.ReadKey(); }
public class MyWebClient : WebClient
{
private IPAddress ipAddress; public MyWebClient(IPAddress ipAddress)
{
this.ipAddress = ipAddress;
} protected override WebRequest GetWebRequest(Uri address)
{
WebRequest request = (WebRequest)base.GetWebRequest(address); ((HttpWebRequest)request).ServicePoint.BindIPEndPointDelegate += (servicePoint, remoteEndPoint, retryCount) =>
{
return new IPEndPoint(ipAddress, );
// IPAddress ipAddress = IPAddress.Parse("192.168.1.82");
}; return request;
}
}

关于http请求指定本地ip的更多相关文章

  1. curl请求指定host ip(指定域名解析的内网某ip)

    域名www.test.com解析内部多台ip $httpHeader = array('Host: www.test.com');$url = "10.17.2.245/xxx/xxx/t. ...

  2. 127.0.0.1 拒绝了我们的连接请求--访问本地IP时显示拒绝访问

    问题描述 今天在访问http://127.0.0.1时,浏览器显示"127.0.0.1 拒绝了我们的连接请求",需要设置浏览器设置 解决方法 1.打开控制面板,搜索"程序 ...

  3. java 获取请求ip,服务本地ip

    /** * 获取请求IP * * @param request * @return */ public static String getRequestIpAddress(HttpServletReq ...

  4. 请求一个域名ip的缓存用处

    前言 摘录自操作系统,这一段的内容很有启发,稍微加上自己的理解,写一篇博客记录一下. 缓存 缓存成功解决了速度不匹配设备之间的数据传输,并且在一般情况下,是整个系统的瓶颈:缓存的出现,有效减少了低速I ...

  5. java网络访问指定出口ip

    java网络访问指定出口ip Table of Contents 1. socket 2. apache httpclient 1 socket 可以在Socket构造函数中指定使用的本地ip,如: ...

  6. GetIPAddress——获得本地IP地址信息

    1.gethostname()需要初始化套接字库 加载#pragma comment(lib,"ws2_32.lib"),和WSAStartup(MAKEWORD(2,2),&am ...

  7. session 关于localhost和本地IP地址 不共享问题

    打比方,  一个请求 localhost:8080/test/test  ,一个本地Ip(172.1.1.1:8080/test/test) 1.请求localhost方式 HttpSession s ...

  8. 多IP指定出口IP地址 如何指定云服务器源IP?

    如果一个主机绑定有多个IP地址,那么在被动响应和主动发起连接两种方式中,源IP地址的选择机制肯定是有所差异的.主机在接收外部数据包,并发送响应数据包时,响应源地址显然就是客户端请求的地址,这是非常容易 ...

  9. 查询本地ip以及ip地址库查询

    四种方法查询本地ip from urllib2 import urlopen from json import load my_ip = urlopen('http://ip.42.pl/raw'). ...

随机推荐

  1. spring在web.xml中的配置

    在实际项目中spring的配置文件applicationcontext.xml是通过spring提供的加载机制,自动加载的容器中去,在web项目中,配置文件加载到web容器中进行解析,目前,sprin ...

  2. Hive总结(五)hive日志

    日志记录了程序执行的过程.是一种查找问题的利器. Hive中的日志分为两种 1. 系统日志,记录了hive的执行情况,错误状况. 2. Job 日志,记录了Hive 中job的运行的历史过程. 系统日 ...

  3. Android简单实现Socket通信,client连接server后,server向client发送文字数据

    案例实现的是简单的Socket通信,当client(Androidclient)连接到指定server以后,server向client发送一句话文字信息(你能够拓展其他的了) 先看一下服务端程序的实现 ...

  4. C#中结构struct的使用

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. 关于ajax访问express服务器的跨域问题

    在学习es6的时候用promise封装了一个ajax <script type="text/javascript"> function getNews(URL) { l ...

  6. 73,QT指针数组实战(指针数组与数组指针)

    //指针数组,每一个指针都是一个MainWindow // MainWindow *w[3][4]; // for(int i=0;i<3;i++) // { // for(int j=0;j& ...

  7. 56.lambda表达式与绑定以及伪函数和绑定

    #include <iostream> #include <functional> using namespace std; using namespace std::plac ...

  8. POJ 3175 枚举

    思路: 枚举小数点前 的数是啥 判一判 复杂度是根号的-.. 注意精度!!!! //By SiriusRen #include <cmath> #include <cstdio> ...

  9. 设置https验证方式

    if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))

  10. Codeforces Round #196 (Div. 2) 少部分题解

    A:sort以后求差值最小 ]; int main() { int n,m; cin>>n>>m; ; i < m ; i++) cin>>a[i]; sor ...