🔔 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
- Checks Internet connectivity every few seconds
- Detects when the connection drops
- Plays a sound alert using pygame
- Runs on Windows, Linux, macOS, or Raspberry Pi
- Uses requests for fast connection checks
🧰 Requirements
- Python 3.x
requestslibrarypygamelibrary- An MP3 or WAV sound file
📜 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
- The script pings Google every 5 seconds
- If the request fails → it assumes the Internet is down
- It plays your chosen sound file using pygame
- Then continues monitoring indefinitely
🚀 Optional Improvements
- Change the check interval (default: 5 seconds)
- Use a WAV file for faster playback
- Send notifications instead of sound
- Log outages to a file
- Run as a background service (systemd / Task Scheduler)