How can I cut off/block all traffic when I lock the screen (and resume when unlocking) in MacOS? Looking to block all network traffic anytime I am away from the computer. I tried putting the iMac to sleep every time I step away and changed the sleep mode to hibernation as well changed energy saving settings to disable network traffic and Wake on LAN, and Powernap is disabled, but my router reports that my iMac still is doing network communication after I put it to sleep. 

I am looking to prevent this. 

Any script I can run when I lock the computer?

[EDIT]

It seems I can run this command as a script: 

/usr/libexec/ApplicationFirewall/socketfilterfw --setblockall on


The problem is it won't work unless I sudo it, and I don't want to have to put in a password every time I lock the screen so this script runs. 

Is there any way around this short of removing the need to provide a password to sudo?
This is almost as fast as having a lock script. Basically, just turn your ethernet interface(s) off/on.


in a terminal run 'sudo -s' 
before locking run 'ifconfig en1 down'
after unlocking run  'ifconfig en1 up'
leave the terminal open but just minimize it for later use


if you don't know which is your active interface, run ifconfig and look for the entry with an IP Address. In the example above, my WiFi interface is en1.
** if you have multiple interfaces just concatenate the command:
'ifconfig en1 down &amp;&amp; ifconfig en2 down' …&amp;etc as needed.