Skip to content

Instantly share code, notes, and snippets.

@npilk
Created April 25, 2022 17:42
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 npilk/a2663e1af3f7e6b93da8634268852e5e to your computer and use it in GitHub Desktop.
Save npilk/a2663e1af3f7e6b93da8634268852e5e to your computer and use it in GitHub Desktop.
python script that toggles DNS blocking when a landline phone is taken on or off the hook (using a Raspberry Pi + door sensor)
import RPi.GPIO as GPIO
import time
import subprocess
# input/output setup for the door sensor
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.IN, pull_up_down = GPIO.PUD_UP)
is_off_hook = None
old_off_hook = None
while True:
old_off_hook = is_off_hook
is_off_hook = GPIO.input(7)
if (is_off_hook and (is_off_hook != old_off_hook)):
print("Phone taken off the hook")
# this script enables DNS blocking by moving a custom configuration file into /etc/dnsmasq.d/
subprocess.call(['sh', '/path/to/script/block.sh'])
elif (is_off_hook != old_off_hook):
print("Phone back on the hook")
# this script turns off DNS blocking by removing the custom configuration file from /etc/dnsmasq.d/
subprocess.call(['sh', '/path/to/script/unblock.sh'])
else:
print("No change")
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment