1

I have a website where I want to display a link ONLY for users inside our local corporate network.

Therefore I have to detect this using Javascript.

I've tried to "ping" a test website hosted on one of our local IIS server with Ajax, but my website is using HTTPS so it does not work (as it seems impossible to issue a SSL certificate for a local server) as all recent browsers raise a "ERR_CERT_AUTHORITY_INVALID" error.

Does anyboby have a clue or an idea on how I can do that?

Here is my current test (which does not work...)

$.ajax({
    type: "GET",
    url: "https://my-local-website.com",
    timeout: 3000,
    jsonp: "jsonp",
    success: function (response, textS, xhr) { 
         $('body').html('true');
    },
    error: function (xmlHttpRequest, textStatus, errorThrown) {
         $('body').html('false');
    }
});
VinZ
  • 360
  • 3
  • 18
  • Why do you need SSL for testing? (You can create a certificate for localhost, but you'll need to either run your own CA or use command line tools and a self signed certificate. In the latter case manually adding to the browser's certificate store as trusted.) – Richard Apr 06 '18 at 06:40
  • you can get clients IP address and check if it's same as yours or thing like that. – Muhammad Usman Apr 06 '18 at 06:43

1 Answers1

0

Follow this topic to get the function that can determine the current IP of the user.

Can You Get A Users Local LAN IP Address Via JavaScript?

And then you use substring or any string method that you prefer to get some parts of the local IP that match with your local corporate network. For example, 192.167..

holydragon
  • 6,158
  • 6
  • 39
  • 62