浏览代码

Added the Network Monitor Code

master
Marcel Haazen 5 年前
父节点
当前提交
af4923c98a
共有 1 个文件被更改,包括 27 次插入0 次删除
  1. +27
    -0
      monitor.cr

+ 27
- 0
monitor.cr 查看文件

@ -0,0 +1,27 @@
# Kitten Info
# Required Modules
require "http/client"
# Network Status
client = HTTP::Client.new("google.com")
# Set Timeouts to 1.5 seconds
client.connect_timeout = 1.5
client.dns_timeout = 1.5
begin
response = client.get("/")
network = "Connected"
rescue Socket::Error
# Disconnect due to DNS error and usually no network access
network = "Disconnected"
rescue IO::Timeout
# Network Timeout
network = "Timeout"
rescue errno
# Disconnect due unreachable host
network = "Disconnected"
end
#Print Information
puts "Internet: " + network

正在加载...
取消
保存