GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Python-Packet-Loss-Monitor/pinger.py at main · drobin04/Python-Packet-Loss-Monitor Expand file tree/ Copy pathpinger.pyMore file actions 54 lines (42 loc) · 1.55 KB / Copy pathpinger.pyFile metadata and controls54 lines (42 loc) · 1.55 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 import os import ping3 import sqlite3 import time database_file = 'results.s3db' # Specify the IP address you want to ping ip_address = '8.8.8.8' def create_database(): conn = sqlite3.connect(database_file) cursor = conn.cursor() cursor.execute(''' CREATE TABLE IF NOT EXISTS packet_loss ( id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp DATETIME DEFAULT CURRENT_TIMESTAMP, error_message TEXT ) ''') conn.commit() conn.close() def ping_and_store(ip_address): create_database() conn = sqlite3.connect(database_file) cursor = conn.cursor() while True: try: ping_time = ping3.ping(ip_address) if ping_time is None or ping_time > 0.5: timestamp = time.strftime('%Y-%m-%d %H:%M:%S') error_message = 'Timeout' if ping_time is None else 'Ping time exceeded 500ms' cursor.execute('INSERT INTO packet_loss (timestamp, error_message) VALUES (?, ?)', (timestamp, error_message)) conn.commit() print('Ping failed:', timestamp, error_message) else: print('Ping success:', round(ping_time * 1000, 2), 'ms') except Exception as e: timestamp = time.strftime('%Y-%m-%d %H:%M:%S') cursor.execute('INSERT INTO packet_loss (timestamp, error_message) VALUES (?, ?)', (timestamp, str(e))) conn.commit() print('Ping failed:', timestamp, str(e)) time.sleep(1) conn.close() ping_and_store(ip_address) |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |