MCPcopy Create free account
hub / github.com/Mister-leo/fssh / ParseProxyCommand

Function ParseProxyCommand

internal/sshconfig/hostconfig.go:188–228  ·  view source on GitHub ↗

ParseProxyCommand attempts to parse an existing ProxyCommand

(cmd string)

Source from the content-addressed store, hash-verified

186
187// ParseProxyCommand attempts to parse an existing ProxyCommand
188func ParseProxyCommand(cmd string) (*ProxyConfig, error) {
189 cmd = strings.TrimSpace(cmd)
190 if cmd == "" {
191 return nil, errors.New("empty proxy command")
192 }
193
194 cfg := &ProxyConfig{Type: ProxyTypeCustom}
195
196 // Try to detect SOCKS5 with nc
197 if strings.Contains(cmd, "nc -X 5 -x") {
198 cfg.Type = ProxyTypeSocks5NC
199 // Extract host:port pattern
200 parts := strings.Fields(cmd)
201 for i, part := range parts {
202 if part == "-x" && i+1 < len(parts) {
203 hostPort := parts[i+1]
204 if idx := strings.Index(hostPort, ":"); idx > 0 {
205 cfg.Host = hostPort[:idx]
206 cfg.Port = hostPort[idx+1:]
207 }
208 break
209 }
210 }
211 } else if strings.Contains(cmd, "ncat --proxy-type socks5") {
212 cfg.Type = ProxyTypeSocks5NCAT
213 // Extract from --proxy
214 parts := strings.Fields(cmd)
215 for i, part := range parts {
216 if part == "--proxy" && i+1 < len(parts) {
217 hostPort := parts[i+1]
218 if idx := strings.Index(hostPort, ":"); idx > 0 {
219 cfg.Host = hostPort[:idx]
220 cfg.Port = hostPort[idx+1:]
221 }
222 break
223 }
224 }
225 }
226
227 return cfg, nil
228}
229
230// ParseProxyJump parses an existing ProxyJump configuration
231func ParseProxyJump(jump string) (*ProxyConfig, error) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected