package main
import (
"fmt"
"log"
"net/http"
"os"
"os/exec"
"strings"
)
func main() {
port := "8080" // 默认端口为 8080
// 从命令行参数获取自定义端口
if len(os.Args) > 1 {
port = os.Args[1]
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
cmd := exec.Command("wget -qO- http://$(ss -nltp | awk '/cloudflared/{print $4}')/quicktunnel | cut -d\" -f4")
output, err := cmd.Output()
if err != nil {
log.Fatal(err)
}
// 将命令输出转换为字符串
result := string(output)
// 生成HTML响应
html := "<html><head><title>Directory Listing</title></head><body><pre>" + result + "</pre></body></html>"
// 将HTML响应写入到HTTP响应中
fmt.Fprintf(w, "%s", html)
})
// 启动HTTP服务器
log.Printf("Server running on port %s\n", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}