-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
47 lines (41 loc) · 988 Bytes
/
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
package main
import (
"bufio"
"crypto/tls"
"fmt"
"log"
"os"
"regexp"
"strings"
"sync"
)
var re = regexp.MustCompile("[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))")
func main() {
config := tls.Config{Certificates: []tls.Certificate{}, InsecureSkipVerify: false}
conn, err := tls.Dial("tcp", "koukoku.shadan.open.ad.jp:992", &config)
if err != nil {
log.Fatalf("client: dial: %s", err)
}
defer conn.Close()
log.Println("client: connected to: ", conn.RemoteAddr())
fmt.Fprintln(conn, "nobody")
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
scanner := bufio.NewScanner(conn)
for scanner.Scan() {
line := strings.TrimSpace(re.ReplaceAllString(scanner.Text(), ""))
fmt.Println(line)
}
}()
wg.Add(1)
go func() {
defer wg.Done()
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
fmt.Fprintln(conn, scanner.Text())
}
}()
wg.Wait()
}