go 远程开关机的代码,因为刚接触go,时间又赶,没做优化,在此记录一下,免得过后忘了。
package main
import (
"flag"
"fmt"
"log"
"net"
"os/exec"
"reflect"
)
var (
arg string
)
func init() {
flag.StringVar(&arg, "uFlags", "", "shutdown")
}
func main() {
Startup()
ShutDownEXE()
/*
flag.Parse()
switch arg {
case "shutdown":
ReShutDownEXE()
default:
fmt.Println("您输入的参数有误.")
}
*/
}
func ShutDownEXE() {
fmt.Println("远程关闭目标机")
arg := []string{"-m", "\\\\10.1.16.56", "-s", "-t", "20"}
cmd := exec.Command("shutdown", arg...)
d, err := cmd.CombinedOutput()
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println(string(d))
return
}
func Startup() {
addr := "10.1.16.255:20000" //定义主机名
//addr := "25