Created
November 13, 2019 09:47
-
-
Save moyashi/6c6c655e894362dd6040c4213eb82703 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;-------------------------------- 設定 ---------------------------------- | |
TETHERING_SSIDS = {"iPhone 7 Plus", "iPhone 8 Plus"} | |
PASSWORD = "0000" | |
;-------------------------------------------------------------------------- | |
DEBUG = true | |
;-------------------------------------------------------------------------- | |
function setApplicationFirewall(arg) | |
hs.execute("echo " .. PASSWORD .. " | sudo -S /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate " .. arg) | |
end | |
function ssidChangedCallback(watcher, msg, interface) | |
local currentSSID = hs.wifi.currentNetwork() | |
if DEBUG then | |
hs.console.printStyledtext(currentSSID) | |
end | |
local matched = false | |
for i,m in ipairs(TETHERING_SSIDS) do | |
if m == currentSSID then | |
matched = true | |
break | |
end | |
end | |
if matched == false then | |
if DEBUG then | |
hs.console.printStyledtext("Firewall Off") | |
end | |
setApplicationFirewall("off") | |
else | |
setApplicationFirewall("on") | |
if DEBUG then | |
hs.console.printStyledtext("Firewall On") | |
end | |
end | |
end | |
hs.wifi.watcher.new(ssidChangedCallback):start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment