Today I am running Mathematica from a computer that is permanently connected to our university network. Because of a number of reasons, I am not allowed to disconnect my computer from our network.

My conflict is that I have some code I wish to test that depends on whether the computer is connected to the Internet or otherwise. How can I pretend my computer is not connected to the Internet for testing?

I know about $NetworkConnected to check if the computer is connected, but temporarily setting it to False with Block does not seem to work.

As a simple example of code that needs an Internet connection for testing purposes, you can use CurrencyConvert.


You can set $AllowInternet to False (or just turn off your WiFi or unplug the cable).

  • $\begingroup$ $AllowInternet looks like it does what I need, but I did not find this in documentation. $\endgroup$ Sep 5 '19 at 16:29
  • 1
    $\begingroup$ @宮元亜衣 You can turn off accessing the internet using the GUI in the preferences. I believe $AllowInternet does exactly the same (and toggling the GUI toggles this variable too). I don't know where it's documented. It's probably undocumented (but widely known). $\endgroup$
    – Szabolcs
    Sep 5 '19 at 16:33
  • 2
    $\begingroup$ For limited documentation use Names["*Internet*"] followed by ??$AllowInternet $\endgroup$
    – Bob Hanlon
    Sep 5 '19 at 16:52

A general solution for Windows is to run an application (such as Mathematica) inside a Sandboxie sandbox, for which Sandbox Settings > Restrictions > Internet Access has been set to "No program can access the Internet."


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.