-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
63 lines (48 loc) · 1.11 KB
/
main.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 (
"fmt"
"net"
"os"
"os/signal"
"syscall"
)
var counter int = 0
func handleConnection(conn net.Conn) {
defer conn.Close()
counter++
var welcomeMessage = fmt.Sprintf(`
You must use UTF-8 Encoding to view this page!!
Welcome to the telnet.qqey.net!
You are the %d th access human!
Your IP Address is %s
Web: https://qqey.net
GitHub Organization: https://github.com/qqey
`, counter, conn.RemoteAddr())
conn.Write([]byte(welcomeMessage))
}
func main() {
listener, err := net.Listen("tcp", ":23")
if err != nil {
fmt.Println("Error listening:", err)
os.Exit(1)
}
defer listener.Close()
fmt.Println("TCP server is listening on port 23")
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigChan
fmt.Println("Shutting down the server...")
listener.Close()
os.Exit(0)
}()
for {
conn, err := listener.Accept()
fmt.Println(conn.RemoteAddr())
if err != nil {
fmt.Println("Error accepting connection:", err)
continue
}
go handleConnection(conn)
}
}