Search code examples
pythonpython-3.xautomationpython-requestswifi

How to check when new device has connected to Wifi in Python


I wanted to build a script that would turn off my Philips Hue lights in my room whenever my PlayStation would turn on/connect to the wifi. I got the lights part down but i don’t know how to check if my PlayStation or a new device has connected to the wifi. Any help would be appreciated. (I’m a beginner at python and coding in general)


Solution

  • In your router config setup then assign a static IP address to your playstation.

    Then your python script just has to ping that IP address to see if it is online or not

    subprocess.check_output(["ping", "-c", "1", "192.1.1.123"])
    

    This will return true if the device is online