Skip to content

Commit d97f7d5

Browse files
committed
new change
1 parent 9c04020 commit d97f7d5

File tree

8 files changed

+148
-42
lines changed

8 files changed

+148
-42
lines changed

cmd/frpc/main.go

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,29 @@ import (
44
"fmt"
55
"log"
66
"net"
7-
"os"
8-
9-
"github.com/BurntSushi/toml"
107
)
118

12-
type ProxyConfig struct {
13-
Name string `toml:"name"`
14-
Type string `toml:"type"`
15-
LocalPort int `toml:"localPort"`
16-
RemotePort int `toml:"remotePort"`
17-
}
18-
19-
type FrpcConfig struct {
20-
Proxies []ProxyConfig `toml:"proxies"`
21-
}
22-
239
func main() {
2410
fmt.Println("Starting PolyProxy client (frpc)...")
2511

26-
// Load configuration
27-
configPath := "../../configs/example_frpc.toml"
28-
if _, err := os.Stat(configPath); os.IsNotExist(err) {
29-
log.Fatalf("Config file not found: %s", configPath)
12+
conn, err := net.Dial("tcp", "127.0.0.1:7000")
13+
if err != nil {
14+
log.Fatalf("Failed to connect: %v", err)
3015
}
16+
defer conn.Close()
3117

32-
var cfg FrpcConfig
33-
if _, err := toml.DecodeFile(configPath, &cfg); err != nil {
34-
log.Fatalf("Error decoding config: %v", err)
18+
message := "Hello from frpc client!"
19+
fmt.Println("Sending:", message)
20+
_, err = conn.Write([]byte(message))
21+
if err != nil {
22+
log.Fatalf("Failed to send message: %v", err)
3523
}
3624

37-
// Connect to each proxy defined in config
38-
for _, proxy := range cfg.Proxies {
39-
address := fmt.Sprintf("127.0.0.1:%d", proxy.RemotePort)
40-
conn, err := net.Dial("tcp", address)
41-
if err != nil {
42-
log.Printf("[%s] Failed to connect: %v", proxy.Name, err)
43-
continue
44-
}
45-
defer conn.Close()
46-
47-
message := fmt.Sprintf("Hello from %s!", proxy.Name)
48-
fmt.Printf("[%s] Sending: %s\n", proxy.Name, message)
49-
conn.Write([]byte(message))
50-
51-
buffer := make([]byte, 1024)
52-
n, err := conn.Read(buffer)
53-
if err != nil {
54-
log.Printf("[%s] Error reading: %v", proxy.Name, err)
55-
continue
56-
}
57-
fmt.Printf("[%s] Server replied: %s\n", proxy.Name, string(buffer[:n]))
25+
// Read server response
26+
buffer := make([]byte, 1024)
27+
n, err := conn.Read(buffer)
28+
if err != nil {
29+
log.Fatalf("Error reading: %v", err)
5830
}
31+
fmt.Println("Server replied:", string(buffer[:n]))
5932
}

cmd/frps/frp

2.77 MB
Binary file not shown.

cmd/frps/frps

2.77 MB
Binary file not shown.

cmd/frps/main.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"net"
7+
)
8+
9+
func main() {
10+
port := "7000"
11+
fmt.Println("Starting PolyProxy server (frps)...")
12+
ln, err := net.Listen("tcp", ":"+port)
13+
if err != nil {
14+
log.Fatalf("Failed to start server: %v", err)
15+
}
16+
defer ln.Close()
17+
fmt.Printf("Server is listening on port %s...\n", port)
18+
19+
for {
20+
conn, err := ln.Accept()
21+
if err != nil {
22+
log.Printf("Failed to accept connection: %v", err)
23+
continue
24+
}
25+
go handleConnection(conn)
26+
}
27+
}
28+
29+
func handleConnection(conn net.Conn) {
30+
defer conn.Close()
31+
fmt.Println("New client connected:", conn.RemoteAddr())
32+
33+
buffer := make([]byte, 1024)
34+
n, err := conn.Read(buffer)
35+
if err != nil {
36+
log.Printf("Error reading from client: %v", err)
37+
return
38+
}
39+
40+
message := string(buffer[:n])
41+
fmt.Println("Received from client:", message)
42+
43+
// Send response back
44+
conn.Write([]byte("Server received: " + message))
45+
}

configs/example_frpc.toml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# FRP client configuration (example_frpc.toml)
2+
3+
[common]
4+
server_addr = "127.0.0.1"
5+
server_port = 7000
6+
# Optional: client identity token (if server uses token auth)
7+
# auth_token = "supersecret"
8+
9+
################################################################################
10+
# 1) Simple TCP proxy (expose local TCP service)
11+
################################################################################
12+
[[proxies]]
13+
name = "ssh_local"
14+
type = "tcp"
15+
local_ip = "127.0.0.1"
16+
local_port = 22
17+
remote_port = 6000
18+
19+
################################################################################
20+
# 2) HTTP proxy plugin (plugin runs on client side to provide an HTTP proxy)
21+
# Connect to it as: http://user123:pass123@<frps_ip>:6001
22+
################################################################################
23+
[[proxies]]
24+
name = "http_proxy_test"
25+
type = "tcp" # plugin sits on top of tcp forwarding
26+
remote_port = 6001
27+
28+
[proxies.plugin]
29+
type = "http_proxy"
30+
http_user = "user123"
31+
http_password = "pass123"
32+
33+
################################################################################
34+
# 3) SOCKS5 plugin (SOCKS tunnel). Connect via SOCKS5 client to remote_port.
35+
################################################################################
36+
[[proxies]]
37+
name = "socks5_proxy"
38+
type = "tcp"
39+
remote_port = 6002
40+
41+
[proxies.plugin]
42+
type = "socks5"
43+
socks5_user = "socksuser"
44+
socks5_password = "sockspass"
45+
46+
################################################################################
47+
# 4) Port Range Mapping (creates many proxies using template - v0.56.0 style)
48+
# This snippet shows how you would write the template. Your client must
49+
# support template expansion (as FRP does) for this to take effect.
50+
################################################################################
51+
# NOTE: Your implementation must support parseNumberRangePair template function
52+
# to expand the following block. Save this text as a fragment and include it
53+
# or place it in your frpc template-enabled config.
54+
{{- range $_, $v := parseNumberRangePair "7000-7003" "7000-7003" }}
55+
[[proxies]]
56+
name = "tcp-{{ $v.First }}"
57+
type = "tcp"
58+
local_port = {{ $v.First }}
59+
remote_port = {{ $v.Second }}
60+
{{- end }}

configs/example_frps.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# FRP server configuration (example_frps.toml)
2+
3+
[common]
4+
# port for frpc to connect to frps
5+
bind_port = 7000
6+
7+
# optional dashboard
8+
dashboard_addr = "0.0.0.0"
9+
dashboard_port = 7500
10+
dashboard_user = "admin"
11+
dashboard_pwd = "admin"
12+
13+
# vhost example (optional)
14+
vhost_http_port = 8080
15+
vhost_https_port = 8443
16+
17+
# allow port ranges if you want to limit what remote ports may be used
18+
# allow_ports = [
19+
# { start = 2000, end = 3000 },
20+
# { single = 6000 }
21+
# ]

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module polyproxy
2+
3+
go 1.22.2
4+
5+
require github.com/BurntSushi/toml v1.5.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
2+
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=

0 commit comments

Comments
 (0)