-
Notifications
You must be signed in to change notification settings - Fork 0
/
bypass1.go
51 lines (43 loc) · 1.05 KB
/
bypass1.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
package main
import (
"fmt"
"net"
)
const (
maxConnectionsPerIP = 10
)
var (
// A map to store the number of connections from each IP address
ipConnections = make(map[string]int)
)
func handleConnection(conn net.Conn) {
// Increment the connection count for the IP address
ipConnections[conn.RemoteAddr().String()]++
// Check if the connection count for the IP address has exceeded the maximum allowed
if ipConnections[conn.RemoteAddr().String()] > maxConnectionsPerIP {
fmt.Println("Connection limit exceeded for IP address:", conn.RemoteAddr().String())
conn.Close()
return
}
// Handle the connection as normal
fmt.Println("Handling connection from:", conn.RemoteAddr().String())
// ...
}
func main() {
// Bind to a port and listen for incoming connections
ln, err := net.Listen("tcp", ":8080")
if err != nil {
fmt.Println(err)
return
}
defer ln.Close()
// Accept connections and handle them in a separate goroutine
for {
conn, err := ln.Accept()
if err != nil {
fmt.Println(err)
continue
}
go handleConnection(conn)
}
}