Skip to content

Instantly share code, notes, and snippets.

@moyashi
Created November 13, 2019 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moyashi/6c6c655e894362dd6040c4213eb82703 to your computer and use it in GitHub Desktop.
Save moyashi/6c6c655e894362dd6040c4213eb82703 to your computer and use it in GitHub Desktop.
;-------------------------------- 設定 ----------------------------------
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