How to by pass network using WebProxy?

岁酱吖の 提交于 2019-12-06 08:15:52

问题


If I want to bypass a Network like 192.168.1.0/24 using webProxy is there any way?

WebProxy proxy = new WebProxy();

proxy.ByPassList = ???

回答1:


You could set it up in Internet Explorer and then use

WebProxy proxy = (WebProxy) WebProxy.GetDefaultProxy(); Deprecated.

var iproxy = WebRequest.GetSystemWebProxy();
var url = new Uri("http://www.example.com");
var wp = new WebProxy();
wp.Credentials = iproxy.Credentials;
wp.Address = iproxy.GetProxy(url);

or you could try to add "192.\.168\.1\.*" to proxy.BypassList with something like

List<string> bypasslist = new List<string>(proxy.BypassList);
bypasslist.Add("192.\.168\.1\.*");
proxy.BypassList = bypasslist.ToArray();



回答2:


You cannot alter the bypass list after the proxy creation. Use the following constructor overloads:

Uri address = ...
proxy = new WebProxy(address, **true**); 

true means "bypass on local", and should be enough for you needs if you are using a 192.168.1.0/24 subnet.

or if you want to add a custom list:

Uri address = ...
proxy = new WebProxy(address, true, new string[] {"192.168.1.1","intranet",...});


来源:https://stackoverflow.com/questions/1796922/how-to-by-pass-network-using-webproxy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!