Skip to main content

monitor internet connection

A Python module to monitor the uptime of the Internet connection in real-time and record the time and duration of any downtime.

Sample output

--------------------------------------------------------------
--------------------------------------------------------------
Monitoring Internet Connection commencing : 2020-01-10 10:34:45 polling every 1 second(s)
-------Internet Connection unavailable at : 2020-01-11 07:35:01
-------Internet Connection restored at    : 2020-01-11 07:35:10
-------The duration of the downtime was   :             0:00:09
-------Internet Connection unavailable at : 2020-01-12 08:35:20
-------Internet Connection restored at    : 2020-01-12 08:36:27
-------The duration of the downtime was   :             0:01:07
Monitoring Internet Connection stopped at : 2020-01-13 12:42:38

What is monitor_internet_connection?

It is a Python module to monitor the uptime of the Internet connection - that is to say to monitor that an external IP address is always reachable.

Why should I use monitor_internet_connection?

If you have automated long-running processes/programs/activities on your computer that requires Internet connectivity, there is nothing worse than coming back the next hour/day/week/whenever to review the logs/progress and find out that the program(s) failed or data is missing because of lost Internet connectivity. What is worse - you may not know exactly when Internet connectivity was lost. Thus, will you need to rerun the entire program/process? Or just a part of it? and so on.

The Python module monitor_internet_connection is a solution to this problem in that it monitors Internet connectivity in real-time, displaying on the console/terminal and recording to a log file: the start time, the end time and the duration of any Internet connectivity downtime. You may simply run this module in a console/terminal and leave it running for days/weeks on end.

What does monitor_internet_connection do?

Every X seconds (default polling frequency is 1 second), the program monitors whether the Internet connection is alive and an external IP address is reachable.

If the Internet is unreachable:

  1. The first observed time of failure is logged.

  2. Every one-minute interval of subsequent unavailability is logged. The one-minute logs can be useful as a proxy indicator of whether the computer lost power or just the Internet connection was unavailable.

  3. When Internet connectivity is restored, the first observed time of restoration is logged.

  4. Finally, the total time duration of the Internet unavailability is logged.

Log File

  • The log file is called internet_monitor.log.

  • The log file is written to the current working folder.

  • The log file is always appended to, never overwritten.

  • The information written to the log file is also displayed on the console/terminal.

  • The log file may be disabled via a command line parameter. See Usage below.

Prerequisites

You must have Python 3.6 or higher installed.

Installation

pip install monitor_internet_connection

QuickStart

python -m monitor_internet_connection

How do I exit the program

To exit the program, simply press Ctrl-C inside the console/terminal. This will cause the program to exit gracefully.

Usage

usage: python -m monitor_internet_connection [-h] [-n] [-f N]

Monitor the uptime of the Internet connection and record any downtime

optional arguments:
  -h, --help        show this help message and exit
  -n, --no-logfile  do not create a log file (default: False)
  -f N, --freq N    specify polling frequency in seconds (default: 1)

Licence

This project is licensed under the MIT License.

Release files for monitor-internet-connection 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for monitor-internet-connection 1.2.1
File Size Uploaded
monitor-internet-connection-1.2.1.tar.gz 6.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for monitor-internet-connection 1.2.1
File Interpreter ABI Platform
monitor_internet_connection-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 16.4 kB

Release files / monitor-internet-connection-1.2.1.tar.gz

Download URL monitor-internet-connection-1.2.1.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3aa267228e80c7c287ae91dc2f299b902025c679917e42ce6ea5734eef6d4ff6
BLAKE2b-256 checksum
How to use checksums
2b8dc32912b490872ab68987f0a4ef2f6107907e2c96921ad25353e580fd49e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1

Release files / monitor_internet_connection-1.2.1-py3-none-any.whl

Download URL monitor_internet_connection-1.2.1-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b0fd24500e03b8f20d84ff81305e622eb6f827d366dca19c8c4765a38cb8fc94
BLAKE2b-256 checksum
How to use checksums
54a00f2ff760e574b4a7565194adb51e9a44fd82eaad7c1f24d7df0fbbc4513a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 release files

1.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page