指标显示在线/离线在22.04

指标显示在线/离线在22.04

我有一段 Python 代码,可以在我们离线时发送通知。我想知道是否可以在 Ubuntu 22.04 中基于此代码设置可见指示器。连接开启时为绿色,断开时为红色。

此代码一半是我的,一半来自互联网上的教程

# importing required modules
import http.client as httplib
import os
import time

   
i = 1

while i < 10:  
   


    def connection_check(url="www.google.com", timeout=3):
        connection = httplib.HTTPConnection(url, timeout=timeout)

        try:
            connection.request("HEAD", "/")
            connection.close()
            print("Active Connection")
            return True
        except Exception as exep:
            os.system('notify-send  "You are offline !!" --icon="/home/myname/PycharmProjects/net_status/cry.png"')
            print(exep)
            return False

    connection_check("www.google.com", 3)
    
    # wait for 1 minute before the next check

    time.sleep(60)

相关内容