Created
September 15, 2023 05:33
-
-
Save bhuiyanmobasshir94/05f4d432875d9e58cbaecea114bfdc6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import time | |
# Define the target server (e.g., Google's DNS server) | |
target_server = "8.8.8.8" | |
# Define the threshold for considering it as a drop-off (in milliseconds) | |
threshold_ms = 100 # Adjust this value as needed | |
def is_internet_up(): | |
try: | |
response = subprocess.check_output(["ping", "-c", "1", target_server]) | |
response_time = float(response.decode().split("time=")[1].split(" ")[0]) | |
return response_time < threshold_ms | |
except subprocess.CalledProcessError: | |
return False | |
def main(): | |
while True: | |
if is_internet_up(): | |
print("Internet is up") | |
else: | |
print("Internet is down") | |
# Adjust the sleep duration as needed (e.g., check every 5 seconds) | |
time.sleep(5) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment