To test if our computer is connected to a firewall we check if the loginwebpage for this firewall opens. If it times out, the error handling will say it's connected, if it opens (or throws a certificate error as it does in our case) we know we are not connected.
The big problem with this process is that whenever we are already connected, the application hangs until the webpage times out..
Any input is more than welcome, here's the code I use:
public static bool FirewallConnectivityStatus(string url)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Proxy = null;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (HttpStatusCode.OK == response.StatusCode)
{
response.Close();
return false;
}
else
{
return true;
}
}
catch (WebException Ex)
{
if (Ex.Status == WebExceptionStatus.TrustFailure)
{
return false;
}
else
{
return true;
}
}
}
Update In the meantime I have found a socket connection that will allow me far better to create this connection via the IP in stead of the url: C# - Socket to log on to Firewall