I watched a video of someone coding a python script which detects if a specific ip joins the network. If the ip connects a message will be sent.
import subprocess
import os
from decouple import config
IP_NETWORK = config('My Network IP')
IP_DEVICE = config('The target device IP')
proc = subprocess.Popen(["ping", IP_NETWORK], stdout=subprocess.PIPE)
while True:
line = proc.stdout.readline()
if not line:
break
# the real code does filtering here
connected_ip = line.decode('utf-8').split()[3]
if connected_ip == IP_DEVICE:
subprocess.Popen(["say", "Person just connected to the network"])
I get this error though:
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/decouple.py", line 199, in __call__
return self.config(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/decouple.py", line 83, in __call__
return self.get(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/decouple.py", line 68, in get
raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option))
decouple.UndefinedValueError: My Network IP not found. Declare it as envvar or define a default value.
What did I do wrong or can this even work? The video where I found the script was from Kalle Hallden. Thanks for your time!