TransWikia.com

python program for wifi connected devices

Stack Overflow Asked by Utkarsh Trivedi on September 5, 2020

I saw this interesting idea from Kalle Hallden’s video. It is about alerting you when someone’s IP connects to the network

import sys
import subprocess
import os
from decouple import config

IP_NETWORK = config('IP_NETWORK')
IP_DEVICE = config('IP_DEVICE')

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", "Linnea just connected to the network"])

Error

Traceback (most recent call last):
  
File "C:UsersutkarDownloadsnet-listen.py", line 6, in <module>
    IP_NETWORK = config('IP_NETWORK')
  
File "C:UsersutkarAppDataLocalProgramsPythonPython38-32libsite-packagesdecouple.py", line 199, in __call__
    return self.config(*args, **kwargs)
  
File "C:UsersutkarAppDataLocalProgramsPythonPython38-32libsite-packagesdecouple.py", line 83, in __call__
    return self.get(*args, **kwargs)
  
File "C:UsersutkarAppDataLocalProgramsPythonPython38-32libsite-packagesdecouple.py", line 68, in get
    
raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option))
decouple.UndefinedValueError: IP_NETWORK not found. Declare it as envvar or define a default value.


Process returned 1 (0x1)        execution time : 0.150 s
Press any key to continue . . .

One Answer

Seems like you forgot to setup a settings.ini. It should look something like this:

[settings]
IP_Network=YOUR NETWORK IP
IP_DEVICE=YOUR DEVICE IP

Answered by Sumajo on September 5, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP