`import sounddevice as sd
import requests
import socket
import json
Webhook URL
webhook_url = '换成自己的webhook'
Check sound card
def check_sound_card():
devices = sd.query_devices()
sound_card_found = any(device['max_input_channels'] > 0 or device['max_output_channels'] > 0 for device in devices)
status = "正常" if sound_card_found else "异常"
return "声卡状态:" + status
Check microphone
def check_microphone():
devices = sd.query_devices()
microphone_found = any(device['max_input_channels'] > 0 for device in devices)
status = "正常" if microphone_found else "异常"
return "麦克风状态:" + status
Check HDMI interface
def check_hdmi_interface():
hostapis = sd.query_hostapis()
hdmi_found = any('HDMI' in hostapi['name'] for hostapi in hostapis)
status = "正常" if hdmi_found else "异常"
return "HDMI接口状态:" + status
Check network
def check_network():
try:
response = requests.get("https://www.google.com","https://www.youtube.com") # 地址可以自己添加一下
response.raise_for_status()
status = "正常"
ip_address = get_internal_ip_address()
return ["网络状态:" + status, "内网IP地址:" + ip_address]
except requests.exceptions.RequestException:
status = "异常"
return ["网络状态:" + status]
Get internal IP address
def get_internal_ip_address():
ip_address = socket.gethostbyname(socket.gethostname())
return ip_address
Get hostname
def get_hostname():
hostname = socket.gethostname()
return "主机名:" + hostname
Send notification message to enterprise WeChat robot
def push_alert(messages):
data = {
"msgtype": "text",
"text": {
"content": "\n".join(messages)
}
}
headers = {'Content-Type': 'application/json'}
try:
response = requests.post(webhook_url, data=json.dumps(data), headers=headers)
response.raise_for_status()
print("已发送通知消息到企业微信机器人")
except requests.exceptions.RequestException:
print("无法发送通知消息到企业微信机器人")
Main function
def main():
messages = []
messages.append(check_sound_card())
messages.append(check_microphone())
messages.append(check_hdmi_interface())
messages.extend(check_network())
push_alert(messages)
Run the main function
if name == "main":
main()`