Click here to Skip to main content
15,905,322 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to find the users machine IP or any other parameter That can help me to identify whether a system is connected in company domain or outside company domain(connected using VPN)

What I have tried:

private string GetPublicIpAddress()
  {
      var request = (HttpWebRequest)WebRequest.Create("http://ifconfig.me");

      request.UserAgent = "curl"; // this simulate curl linux command

      string publicIPAddress;

      request.Method = "GET";
      using (WebResponse response = request.GetResponse())
      {
          using (var reader = new StreamReader(response.GetResponseStream()))
          {
              publicIPAddress = reader.ReadToEnd();
          }
      }

      return publicIPAddress.Replace("\n", "");
  }
Posted
Updated 27-Jun-17 3:56am
v2

1 solution

Typically, the VPN network is a different subnet. So, you have to find out what that subnet is.

Once you know that, in your request processing you can look at the value in ServerVariables["HTTP_X_FORWARDED_FOR"] for the clients IP. If that returns en empty string, look in ServerVariables["REMOTE_ADDR"] instead and compare to the known VPN subnet.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900