nezha/cmd/playground/main.go

66 lines
1.4 KiB
Go
Raw Normal View History

2019-12-02 09:57:14 -05:00
package main
import (
2021-01-16 01:11:51 -05:00
"crypto/tls"
"fmt"
2019-12-02 09:57:14 -05:00
"log"
"net"
2021-01-16 01:11:51 -05:00
"net/http"
2019-12-02 09:57:14 -05:00
"os/exec"
"time"
2019-12-11 08:50:49 -05:00
"github.com/genkiroid/cert"
"github.com/go-ping/ping"
"github.com/shirou/gopsutil/v3/disk"
2019-12-02 09:57:14 -05:00
)
func main() {
2021-01-16 01:11:51 -05:00
// 跳过 SSL 检查
transCfg := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
httpClient := &http.Client{Transport: transCfg}
_, err := httpClient.Get("https://expired-ecc-dv.ssl.com")
fmt.Println(err)
// SSL 证书信息获取
c := cert.NewCert("expired-ecc-dv.ssl.com")
fmt.Println(c.Error)
// TCP
conn, err := net.DialTimeout("tcp", "example.com:80", time.Second*10)
if err != nil {
panic(err)
}
println(conn)
2021-01-16 01:11:51 -05:00
// ICMP Ping
pinger, err := ping.NewPinger("example.com")
if err != nil {
panic(err)
}
pinger.Count = 3
err = pinger.Run() // Blocks until finished.
if err != nil {
panic(err)
}
fmt.Printf("%+v", pinger.Statistics())
2021-01-16 01:11:51 -05:00
// 硬盘信息
2019-12-11 08:50:49 -05:00
dparts, _ := disk.Partitions(false)
for _, part := range dparts {
u, _ := disk.Usage(part.Mountpoint)
2020-11-21 09:07:34 -05:00
if u != nil {
log.Printf("%s %d %d", part.Device, u.Total, u.Used)
}
2019-12-11 08:50:49 -05:00
}
2019-12-02 09:57:14 -05:00
}
func cmdExec() {
cmd := exec.Command("ping", "example.com", "-c2")
2019-12-02 09:57:14 -05:00
output, err := cmd.Output()
log.Println("output:", string(output))
log.Println("err:", err)
cmd = exec.Command("ping", "example", "-c2")
2019-12-02 09:57:14 -05:00
output, err = cmd.Output()
log.Println("output:", string(output))
log.Println("err:", err)
}