Open-Source Tools & Scripts to Monitor and Log Unstable Internet Connection for ISP Debugging


2 views

When your internet connection flickers like a candle in the wind, even simple tasks become impossible. The classic symptoms - unable to resolve host errors, intermittent ping failures, and random disconnects - make remote work and development unbearable. Traditional ISP support often dismisses these issues as "temporary outages" unless you come armed with hard data.

To properly diagnose connection issues, we need three key metrics:

  1. Packet loss percentage
  2. Latency variance
  3. DNS resolution success rate

Here's a simple Python script using speedtest-cli and ping3:

import speedtest
import ping3
import time
from datetime import datetime

def log_connection():
    st = speedtest.Speedtest()
    while True:
        try:
            timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            ping_time = ping3.ping('google.com', unit='ms')
            download = st.download() / 1_000_000  # Convert to Mbps
            upload = st.upload() / 1_000_000
            
            with open('connection_log.csv', 'a') as f:
                f.write(f"{timestamp},{ping_time},{download:.2f},{upload:.2f}\n")
            
            time.sleep(300)  # Check every 5 minutes
        except Exception as e:
            with open('connection_errors.log', 'a') as f:
                f.write(f"{timestamp} - {str(e)}\n")

For more robust solutions, consider these open-source tools:

Tool Best For Data Collected
SmokePing Latency tracking RTT, packet loss, jitter
Grafana+Prometheus Visualization All metrics with dashboards
PingPlotter Troubleshooting Hop-by-hop analysis

When dealing with particularly stubborn ISPs, running continuous traceroutes can pinpoint exactly where packets are being dropped in the network path. Here's a Bash script that logs traceroutes hourly:

#!/bin/bash

while true
do
    timestamp=$(date +"%Y-%m-%d_%H-%M-%S")
    traceroute -n 8.8.8.8 > "traceroute_${timestamp}.log"
    sleep 3600
done

Combine this with cron jobs to monitor specific services you depend on:

*/5 * * * * curl -Is https://api.yourservice.com | grep HTTP >> /var/log/api_monitor.log

When you finally have enough data to confront your ISP, format it clearly:

  • Time-based correlation charts showing outages
  • Percentage calculations of uptime/downtime
  • Comparative analysis against SLA promises

Remember: ISPs respond better to numbers than anecdotes. A well-documented month of instability with 37% packet loss during business hours is harder to ignore than "my internet keeps dropping."


Dealing with an unstable internet connection is every developer's nightmare - especially when trying to demonstrate the issue to ISP support teams. Random disconnections (manifesting as "unable to resolve host" errors) create productivity roadblocks that standard ping tests can't adequately capture.

The key requirements for effective monitoring:

  • Continuous operation regardless of user activity
  • No privacy-invading tracking of browsing habits
  • Detailed logs with timestamps for evidence
  • Minimal system resource usage

For developers comfortable with terminals, these tools shine:

# Basic continuous ping logger
ping google.com | while read pong; do echo "$(date): $pong" >> pinglog.txt; done

# Advanced tcptraceroute monitoring
sudo apt install tcptraceroute
while true; do date >> netlog.txt; tcptraceroute google.com 80 >> netlog.txt; sleep 60; done

For those preferring visual tools:

  • PingPlotter: Combines traceroute with continuous ping monitoring
  • SmokePing: Tracks latency and packet loss over time
  • PRTG Network Monitor: Free version available for basic monitoring

A simple script to log connection status:

import socket
import time
import datetime

def check_connection(host="8.8.8.8", port=53, timeout=3):
    try:
        socket.setdefaulttimeout(timeout)
        socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
        return True
    except Exception as ex:
        return False

while True:
    timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    status = "ONLINE" if check_connection() else "OFFLINE"
    with open("connection_log.csv", "a") as f:
        f.write(f"{timestamp},{status}\\n")
    time.sleep(60)

When presenting to ISPs, focus on:

  • Downtime frequency patterns
  • Packet loss percentages
  • Consistent latency spikes
  • DNS resolution failures

For 24/7 monitoring without tying up your dev machine:

# On Raspberry Pi
sudo apt install smokeping
sudo systemctl enable smokeping
sudo systemctl start smokeping