ParseProxyCommand attempts to parse an existing ProxyCommand
(cmd string)
| 186 | |
| 187 | // ParseProxyCommand attempts to parse an existing ProxyCommand |
| 188 | func 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 |
| 231 | func ParseProxyJump(jump string) (*ProxyConfig, error) { |
nothing calls this directly
no outgoing calls
no test coverage detected