@@ -25,6 +25,7 @@ type Config struct {
25
25
Address string `json:"address"`
26
26
Host string `json:"host"`
27
27
} `json:"forward"`
28
+ SSH string `json:"ssh"`
28
29
}
29
30
30
31
var c Config
@@ -79,6 +80,12 @@ func handler(conn net.Conn) {
79
80
fmt .Println ("fail to get first packet" )
80
81
return
81
82
}
83
+
84
+ if ( string (p )[:3 ] == "SSH" ) {
85
+ fmt .Println ("SSH packet" )
86
+ sshForward (conn , p )
87
+ return
88
+ }
82
89
if ( strings .Index (string (p ), "Host" ) < 0 ) {
83
90
fmt .Println ("not a http packet" )
84
91
return
@@ -116,6 +123,19 @@ func handler(conn net.Conn) {
116
123
}
117
124
}
118
125
126
+ func sshForward (conn net.Conn , p []byte ) {
127
+ forward , err := net .Dial ("tcp" , c .SSH )
128
+ if err != nil {
129
+ fmt .Println ("connect failed: " , err )
130
+ return
131
+ }
132
+ defer forward .Close ()
133
+ conn .SetReadDeadline (time.Time {})
134
+ forward .Write (p )
135
+ go io .Copy (forward , conn )
136
+ io .Copy (conn , forward )
137
+ }
138
+
119
139
func HostInject (p []byte , host string ) []byte {
120
140
var i int
121
141
flag := 0
@@ -164,7 +184,6 @@ func readJson() {
164
184
}
165
185
166
186
func getJson () {
167
- // url := "http://rss.1m.ee/porter.html"
168
187
timeout := time .Duration (10 * time .Second )
169
188
client := & http.Client {Timeout : timeout }
170
189
req , _ := http .NewRequest ("GET" , config , nil )
0 commit comments