Internet uptime monitor with logging
![internet uptime monitor with logging internet uptime monitor with logging](https://www.webspy.com/wp-content/uploads/2015/10/MicrosoftICFLoader.png)
INTERNET UPTIME MONITOR WITH LOGGING CODE
Finally, we wrap the entire functionality in a loop, as shown in the code below.įILE = os. The next step is to calculate the time the network connection is down. We then verify that we have access to the log file directory and quit if we do not have access. We also pass the port, and since it’s a DNS server, use port 53. For this example, we use Cloudflare public DNS address, which has a very high uptime. We use the socket library to send a request to an external IP address in the first function. Next, we create a log file in the current working directory.
INTERNET UPTIME MONITOR WITH LOGGING HOW TO
Talk is cheap let’s now dive into the code showing how to implement this logic: Now Show Me The CodeĪs usual, in Python, we start by importing the required libraries.
![internet uptime monitor with logging internet uptime monitor with logging](https://uptimerobot.com/assets/images/ogimage.png)
Here’s a flow chart explaining this concept: We also have to be careful when pinging a single server because we can have the ping falsely mistaken as a DDoS attack, which might cause our IP address to get blocked, which would produce negative results. Having the time difference, we can note when the internet was down and for how long. If we ping the server and there’s no response, we note that specific time and continue to ping until we receive a ping and note the time. A ping is a method where we continuously ping a reliable server-perhaps Cloudflare or Google DNS-and then wait for a response. Without complicating our code, we can go with ping. Now that we know what internet downtime is, you may be wondering, “how do we go about determining it?” The longer the internet is unavailable, the longer the downtime. When we talk about network up and downtime, we mean the period where the network connection is entirely unavailable, and thus, we cannot communicate with devices outside our network.
![internet uptime monitor with logging internet uptime monitor with logging](https://www.manageengine.com/network-monitoring/images/Effective-network-monitoring.jpg)
The script we shall create shall also keep logs of when the internet is down and the duration of the downtime: Project Requirementsįor this project, we are only going to need: In today’s tutorial, we will build a simple network monitor that continually monitors your internet connectivity by sending ping requests to an external resource. Thus, having a tool that allows you to monitor when your network goes down can help you troubleshoot the network or stop the applications before sending a bunch of log errors. Having applications and devices that need to log, send, and receive data to the outside world is critical. The need to have our devices always connected to the internet is becoming more of a basic need than an added privilege.