How to by pass network using WebProxy?

shahjapan picture shahjapan · Nov 25, 2009 · Viewed 14.5k times · Source

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 = ???

Answer

Jonas Elfström picture Jonas Elfström · Nov 25, 2009

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();