What is the easiest way to test if a user is connected to our WAN?

RLH

New Member
#1
A bit of background. I work for a corporation that has a global WAN. External users connect to it through a VPN and must be connected to it in order to have access to their emails and, of course, shared network directories.

I have a .Net application that is published and installed from our website using ClickOnce. User's who both do and do not work for the company have access to this application and it sends requests to a web service that is also published to the web server.

For reasons outside the scope of this question, when a user attempts to log into the application they should connect to the web service server by explicitly referencing the the computer name of the server (i.e. http://**server**/webservice/ws.asmx.) If a user is not connected to our WAN, they need to access it through our web address (i.e. https://**www.companywebsite.com**/webservice/ws.asmx.)

I know how to dynamically set the associated URL with the web service. My problem is that I can't think of an fast, reliable and easy way to test for the WAN connection.

Initially I tried to send a ping request (using the .Net Ping class) to the server with a rather short timeout. However, calling a ping operation against the server, when not connected to the WAN, returns an exception that states
An exeception occurred during the Ping request.
Below is the code associated with the property that tests for the WAN connection. It's simple but it keeps giving me above message when I test this off of our network.
Mã:
public static bool ConnectedToWAN
{
  get
  {
    try
    {
      Ping ping = new Ping();
      PingReply reply = ping.Send("server", 2000);
      return reply.Status == IPStatus.Success;
    }
    catch (Exception e)
    {/* ' An exeception occurred during the Ping request.' */};
  }
I would prefer not returning my connection state based off of the exception that I'm getting. Rather, I'd make an explicit call to the network that can validate the connection.

One quick note, I can't check the user's IP. Some of our users work for other organizations that have there own WAN. Since I'm checking their IP within a .Net WinForms application there is a chance that their IP address may be associated with their WAN. Instead, I need to check and see if they are specifically connected to our WAN, not just any WAN.

How can I do this?
 

Admin

Administrator
Thành viên BQT
#2
I think the question is you need to resolve the host name if there are connected within company network rather than public accessible internet.

if that is the case, you can use DNS.BeginGetHostEntry and using asynchronous method to get the domain name system for specified host computer.

e.g
Mã:
var host = '**Internal Server Name**';
Boolean isWANConnected = false;
String ConnectMessage ;
AsyncCallback callBack = new AsyncCallBack(GetHostName);
Dns.BeginGetHostEntry(host, callBack, host);

static void GetHostName(IAsyncResult result)
{
  string hostname = (string)result.AsyncState;
  try
  {
     IPHostEntry host = Dns.EndGetHostEntry(result)
     ConnectMessage = host as String;
  }
  catch(SocketException e)
  {
    isWANConnected = false;
    ConnectMessage = e.Message;
  }
}
 
Top