On my macOS box, I run Little Snitch, a nice UI that can be set to ask local user for explicit permission before allowing a network request.

https://www.obdev.at/products/littlesnitch/index.html

I’ve occasionally stumbled on it during remote logins, usually when an SSH session wants to download something new, like NPM requesting NodeJS bits. The text terminal SSH download will block; if I figure out it’s the Little Snitch then I have to walk all the way to my desk downstairs, wiggle the mouse to wake up the monitor and unlock the screen saver, and click “Allow” on the Little Snitch dialog box.

Works as intended.

BUT by default it’s common to set such things to silently allow local network requests, so I don’t know if such shenanigans in the OP would work in my case.

Little Snitch is amazing.

Any windows comparable?

I’m very happy with SimpleWall: https://github.com/henrypp/simplewall