-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.go
86 lines (74 loc) · 1.63 KB
/
server.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"fmt"
"io"
"net"
"os"
"strings"
"sync"
)
type Client struct {
IPAddress string
}
var Clients []Client
var Requests []string
func listenf() {
ln, err := net.Listen("tcp", _server)
if err != nil {
fmt.Println(Fore["RED"]+"[-]", err,Fore["RESET"])
os.Exit(0)
}
defer ln.Close()
// Accept incoming connections
for {
conn, err := ln.Accept()
if err != nil {
continue
}
// Handle connection in a separate goroutine
go handleConnection(conn)
}
}
func rest() {
// stop = false
v_client = ""
}
var canexit bool = true
func handleConnection(conn net.Conn) {
defer conn.Close()
defer rest()
var addr string = strings.Split(conn.RemoteAddr().String(), ":")[0]
if !contains(addr, Requests) {
Clients = append(Clients, Client{IPAddress: addr})
Requests = append(Requests, addr)
}
if v_client != "" {
if strings.Split(conn.RemoteAddr().String(), ":")[0] == v_client || v_client=="*" {
stop = true
fmt.Println(Fore["GREEN"]+"[+] Connection from "+Fore["BLUE"]+addr+Fore["RESET"])
canexit = false
var wg sync.WaitGroup
wg.Add(2)
tcpconn := conn.(*net.TCPConn)
go func() {
io.Copy(tcpconn, os.Stdin)
fmt.Fprintf(os.Stderr, Fore["RED"]+"[-] Connection Interrupt press ENTER to continue"+Fore["RESET"])
tcpconn.CloseWrite()
tcpconn.CloseRead()
wg.Done()
}()
go func() {
io.Copy(os.Stdout, tcpconn)
fmt.Fprintf(os.Stderr, Fore["RED"]+"[-] Connection Interrupt press ENTER to continue"+Fore["RESET"])
tcpconn.CloseRead()
tcpconn.CloseWrite()
wg.Done()
}()
wg.Wait()
canexit = true
fmt.Printf("\n")
}
}
rest()
conn.Close()
}