HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://ip-api.com/json");
WebProxy proxy = new WebProxy("209.205.2.1", 444);
proxy.Credentials = new NetworkCredential("xiexibi123", "0b8487-516e1e-9826a1-b091c8-a449123");
request.Proxy = proxy;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();//获得回应的数据流
//将数据流转成 String
string result = new StreamReader(stream, System.Text.Encoding.UTF8).ReadToEnd();
textBox1.Text = result;
以上代码 当程序运行起来时 每次执行 都会得到相同的IP
当程序重新启动以后 再次执行 就会得到新的IP
求高手解答 如何控制每次访问web的IP
#python改编了一套
from urllib import request
proxy_support = request.ProxyHandler({'http':'http://xiexibi123:0b8487-516e1e-9826a1-b091c8-a449d9@209.205.212.38:444'})
auth = request.HTTPBasicAuthHandler()
opener = request.build_opener(proxy_support, auth, request.HTTPHandler)
request.install_opener(opener)
response = request.urlopen("http://ip-api.com/json")
html = response.read()
print(html)
#第一次结果
b'{"status":"success","country":"United States","countryCode":"US","region":"NY","regionName":"New York","city":"Buffalo","zip":"14202","lat":42.8943,"lon":-78.8736,"timezone":"America/New_York","isp":"B2 Net Solutions Inc.","org":"ServerMania Inc","as":"AS55286 B2 Net Solutions Inc.","query":"23.236.197.231"}'
#第二次
b'{"status":"success","country":"United States","countryCode":"US","region":"NY","regionName":"New York","city":"Buffalo","zip":"14202","lat":42.8943,"lon":-78.8736,"timezone":"America/New_York","isp":"B2 Net Solutions Inc.","org":"ServerMania Inc","as":"AS55286 B2 Net Solutions Inc.","query":"45.57.203.180"}'
#补充,你把你公司的代理池账户密码公开这样好吗?
#很明显一台主机做分发,访问这台主机需要账户密码,你最后访问接口只不过返回你请求时候的ip而已
#内网屏蔽也没做,就单单账户密码做权限认证,你还写出来骚年
你好 感谢你的回复 首先这是C#代码 python 的运行环境不了解
我遇到的问题是在C#的环境下 正常这个代理服务器 就像你所说的 应该每发送一个数据包 都会换一个IP,但是C#下无法正常的切换IP 所以把最简单demo发出来 请教
@只会造轮子: 原理都是一样的,做分发,你看看你主机做分发的机制是啥,你说第一次都是一样,一样的ip是什么
@只会造轮子: 我用python每次执行生成的都不同,应该不是主机分发机制问题你的代码问题
@小小咸鱼YwY: 已经找到解决办法了 是会话的问题 感谢回复