How can I display an alert if student is on certain IP address?

Jump to solution
dkpatton
Community Participant

My campus has a guest network that students are not supposed to use. Unfortunately, about 10-20% of our students use guest. This has not been a problem until recently when students have used LockDown Browser to take Canvas quizzes. The high latency causes the application to fail. 

In considering solutions, we had an idea that would be very tidy. Using custom code in our sub-account course theme, it should be possible to grab the user's IP address and insert an element on the page that warns them about using the guest network. We could then monitor last-login IP addresses until we are confident that students have configured the secure enterprise network. Then we can disable the function in the template.

I think the solution is going to use our sub-account custom course theme JS. All solutions I've explored so far have used a third-party tool to retrieve the IP address, which would probably fail due to cross-site scripting controls. However, since IP filtering is an option in Quizzes, my hope is that I could read the IP address easily from the session cookies or some other object. However, I can't seem to locate the IP if it indeed stored in an accessible location.

Can my Canvas template get the user's IP address without causing cross-site scripting errors?


Updated: Clarification and Precision.

1 Solution

Hi  @dkpatton ‌

I did a quick test, and it seems that my theory was correct.

Here is the script I used for testing:

$.getJSON( "/api/v1/users/self/page_views", function( data ){
      alert(data[0].remote_ip);
   }
);

This only displays the user's IP address in the alert box, but it should give you a base for your code.

I will also note that this is using jQuery, but since Canvas is dependent on jQuery, you shouldn't need to load any additional libraries.

Alex

View solution in original post