first commit

This commit is contained in:
2023-11-22 14:48:29 +08:00
parent faa44d2c74
commit e78f59fbf0
6 changed files with 99 additions and 0 deletions

24
internal/check.go Normal file
View File

@@ -0,0 +1,24 @@
package internal
import (
"fmt"
"net"
"time"
)
func Check(destination, port string) string {
address := destination + ":" + port
timeout := 5 * time.Second
var status string
conn, err := net.DialTimeout("tcp", address, timeout)
if err != nil {
status = fmt.Sprintf("[下线] %s 无法访问 %v", destination, err)
return status
}
defer func(conn net.Conn) {
_ = conn.Close()
}(conn)
status = fmt.Sprintf("[上线] %s 访问正常\n从: %s\n到: %s", destination, conn.LocalAddr(), conn.RemoteAddr())
return status
}