πŸ”” Python Internet Drop Alarm

A Simple Wi‑Fi / Internet Loss Detector

This project is a lightweight Python-based alarm system that plays a sound whenever your device loses Internet connectivity. The project is not tested, only coded! It continuously checks your connection and alerts you instantly if the network goes down.

It’s ideal for monitoring unstable Wi‑Fi, servers, routers, or any setup where connection uptime is important.

πŸ“‘ What This Project Does

🧰 Requirements

πŸ“œ Full Python Code


import time
import requests
import pygame

# Initialize pygame mixer
pygame.mixer.init()

# Path to your sound file
SOUND_FILE = "soundfile.mp3"

def is_connected():
    try:
        requests.get('https://www.google.com', timeout=5)
        return True
    except requests.ConnectionError:
        return False

def play_sound():
    try:
        pygame.mixer.music.load(SOUND_FILE)
        pygame.mixer.music.play()
        while pygame.mixer.music.get_busy():
            time.sleep(0.1)
    except Exception as e:
        print(f"Error playing sound: {e}")

def monitor_connection(check_interval=5):
    while True:
        if not is_connected():
            print("Internet connection dropped. Playing sound...")
            play_sound()
        else:
            print("Internet connection is up.")
        time.sleep(check_interval)

if __name__ == "__main__":
    monitor_connection()

You can replace the sound file with any alert tone you prefer.

βš™οΈ How It Works

πŸš€ Optional Improvements

πŸ“¦ Download the Project

Find this script and more in the main repository:

πŸ“ View on GitHub