DuckDNS / External Access ON/OFF switch?

Found how easy is to access to others HA, just browsing GitHub brings tons of ip/user/pass and many of them not even locked, those which are locked, many times have open ports and services which are unlocked, and I’ll not even talk about Shodan.

I want to make automation which disable access from Internet and only enabled on LAN,

Such thing exists? any idea how to start?

Wow. That is scary. So many unsecured HA servers.