-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
407 additions
and
767 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.git | ||
.gitignore | ||
.env* | ||
README.md | ||
Dockerfile | ||
docker-compose.yml | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,24 @@ | ||
FROM golang:1.22.5-alpine AS builder | ||
# Install required system packages | ||
RUN apk update && \ | ||
apk upgrade && \ | ||
apk add --no-cache ca-certificates && \ | ||
update-ca-certificates | ||
# Install required packages and set up workspace in a single layer | ||
RUN apk add --no-cache ca-certificates && update-ca-certificates | ||
|
||
WORKDIR /build | ||
|
||
# Copy go mod and source files | ||
COPY go.mod go.sum ./ | ||
COPY *.go ./ | ||
|
||
# Download dependencies | ||
RUN go mod download | ||
# Copy all necessary files in a single layer | ||
COPY . . | ||
|
||
# Build the application | ||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o proxy-server . | ||
RUN go mod download && CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o proxy-server ./cmd/main.go | ||
|
||
# Final stage | ||
# Final stage - minimal image | ||
FROM scratch | ||
WORKDIR /app | ||
COPY --from=builder /build/proxy-server . | ||
|
||
# Copy only the necessary files from builder | ||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
COPY --from=builder /build/proxy-server . | ||
COPY --from=builder /build/proxies.conf ./proxies.conf | ||
COPY --from=builder /build/users.conf ./users.conf | ||
|
||
EXPOSE 1080 | ||
CMD ["./proxy-server"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,237 +5,99 @@ A high-performance SOCKS5 proxy server written in Go that rotates through multip | |
## Features | ||
|
||
- SOCKS5 proxy server with username/password authentication | ||
- Support for multiple upstream proxy protocols: | ||
- HTTP proxies | ||
- HTTPS proxies (encrypted) | ||
- SOCKS5 proxies | ||
- SOCKS5H proxies (proxy performs DNS resolution) | ||
- Multiple proxy protocol support (HTTP, HTTPS, SOCKS5, SOCKS5H) | ||
- Round-robin proxy rotation | ||
- Edge mode for fallback to direct connections | ||
- Multi-user support via configuration file | ||
- Docker and docker-compose support | ||
- Configurable port | ||
- Multi-user support | ||
- Docker support | ||
- Zero runtime dependencies | ||
- Comments support in configuration files | ||
- Automatic proxy failover | ||
- IPv6 support | ||
|
||
## Quick Start with Docker Compose (Recommended) | ||
## Quick Start | ||
|
||
1. Clone the repository: | ||
```bash | ||
git clone https://github.com/ariadata/go-proxy-rotator.git | ||
git clone https://github.com/yourusername/go-proxy-rotator.git | ||
cd go-proxy-rotator | ||
``` | ||
|
||
2. Set up configuration files: | ||
```bash | ||
# Copy environment example | ||
cp .env.example .env | ||
|
||
# Create users file | ||
echo "user1:password1" > users.conf | ||
echo "user2:password2" >> users.conf | ||
|
||
# Create proxies file (add your proxies) | ||
touch proxies.conf | ||
cp users.conf.example users.conf | ||
cp proxies.conf.example proxies.conf | ||
``` | ||
|
||
3. Create `docker-compose.yml`: | ||
```yaml | ||
version: '3.8' | ||
|
||
services: | ||
proxy-rotator: | ||
image: 'ghcr.io/ariadata/go-proxy-rotator:latest' | ||
ports: | ||
- "${DC_SOCKS_PROXY_PORT}:1080" | ||
volumes: | ||
- ./proxies.conf:/app/proxies.conf:ro | ||
- ./users.conf:/app/users.conf:ro | ||
env_file: | ||
- .env | ||
restart: unless-stopped | ||
healthcheck: | ||
test: ["CMD", "nc", "-z", "localhost", "1080"] | ||
interval: 30s | ||
timeout: 10s | ||
retries: 3 | ||
``` | ||
3. Edit the configuration files: | ||
- `users.conf`: Add your username:password pairs | ||
- `proxies.conf`: Add your proxy servers | ||
- `.env`: Adjust settings if needed | ||
|
||
4. Start the service: | ||
4. Run with Docker: | ||
```bash | ||
docker-compose up -d | ||
``` | ||
|
||
5. Test your connection: | ||
```bash | ||
curl --proxy socks5h://user1:password1@localhost:60255 https://api.ipify.org?format=json | ||
``` | ||
|
||
## Installation with Go | ||
|
||
1. Clone and enter the repository: | ||
```bash | ||
git clone https://github.com/ariadata/go-proxy-rotator.git | ||
cd go-proxy-rotator | ||
``` | ||
|
||
2. Install dependencies: | ||
```bash | ||
go mod download | ||
``` | ||
|
||
3. Set up configuration files: | ||
```bash | ||
cp .env.example .env | ||
# Edit users.conf and proxies.conf | ||
``` | ||
|
||
4. Build and run: | ||
```bash | ||
go build -o proxy-server | ||
./proxy-server | ||
docker compose up -d | ||
``` | ||
|
||
## Configuration | ||
|
||
### Environment Variables (.env) | ||
|
||
```env | ||
# Project name for docker-compose | ||
COMPOSE_PROJECT_NAME=go-proxy-rotator | ||
# Port for the SOCKS5 server | ||
DC_SOCKS_PROXY_PORT=60255 | ||
# Enable direct connections when proxies fail | ||
ENABLE_EDGE_MODE=true | ||
``` | ||
|
||
### User Configuration (users.conf) | ||
|
||
Format: | ||
``` | ||
username1:password1 | ||
username2:password2 | ||
# Comments are supported | ||
``` | ||
|
||
### Proxy Configuration (proxies.conf) | ||
|
||
The proxy configuration file supports various proxy formats: | ||
|
||
``` | ||
# HTTP proxies | ||
# HTTP/HTTPS proxies | ||
http://proxy1.example.com:8080 | ||
http://user:[email protected]:8080 | ||
# HTTPS proxies (encrypted connection to proxy) | ||
https://secure-proxy.example.com:8443 | ||
https://user:[email protected]:8443 | ||
# SOCKS5 proxies (standard) | ||
socks5://socks-proxy.example.com:1080 | ||
socks5://user:[email protected]:1080 | ||
https://user:[email protected]:8443 | ||
# SOCKS5H proxies (proxy performs DNS resolution) | ||
socks5h://socks-proxy3.example.com:1080 | ||
socks5h://user:[email protected]:1080 | ||
# IPv6 support | ||
http://[2001:db8::1]:8080 | ||
socks5://user:password@[2001:db8::2]:1080 | ||
# Real-world format examples | ||
http://proxy-user:[email protected]:8080 | ||
https://proxy-user:[email protected]:8443 | ||
socks5://socks-user:[email protected]:1080 | ||
# SOCKS5 proxies | ||
socks5://proxy3.example.com:1080 | ||
socks5h://user:[email protected]:1080 | ||
``` | ||
|
||
## Edge Mode | ||
|
||
When edge mode is enabled (`ENABLE_EDGE_MODE=true`), the server will: | ||
## Testing | ||
|
||
1. First attempt a direct connection | ||
2. If direct connection fails, rotate through available proxies | ||
3. If all proxies fail, return an error | ||
|
||
This is useful for: | ||
- Accessing both internal and external resources | ||
- Reducing latency for local/fast connections | ||
- Automatic failover to direct connection | ||
|
||
## Usage Examples | ||
|
||
### With cURL | ||
Test your connection: | ||
```bash | ||
# Basic usage | ||
curl --proxy socks5h://user:pass@localhost:60255 https://api.ipify.org?format=json | ||
|
||
# With specific DNS resolution | ||
curl --proxy socks5h://user:pass@localhost:60255 https://example.com | ||
|
||
# With insecure mode (skip SSL verification) | ||
curl --proxy socks5h://user:pass@localhost:60255 -k https://example.com | ||
curl --proxy socks5h://username1:password1@localhost:60255 https://api.ipify.org?format=json | ||
``` | ||
|
||
### With Python Requests | ||
```python | ||
import requests | ||
|
||
proxies = { | ||
'http': 'socks5h://user:pass@localhost:60255', | ||
'https': 'socks5h://user:pass@localhost:60255' | ||
} | ||
## Building from Source | ||
|
||
response = requests.get('https://api.ipify.org?format=json', proxies=proxies) | ||
print(response.json()) | ||
```bash | ||
make build | ||
``` | ||
|
||
### With Node.js | ||
```javascript | ||
const SocksProxyAgent = require('socks-proxy-agent'); | ||
|
||
const proxyOptions = { | ||
hostname: 'localhost', | ||
port: 60255, | ||
userId: 'user', | ||
password: 'pass', | ||
protocol: 'socks5:' | ||
}; | ||
|
||
const agent = new SocksProxyAgent(proxyOptions); | ||
## Docker Commands | ||
|
||
fetch('https://api.ipify.org?format=json', { agent }) | ||
.then(res => res.json()) | ||
.then(data => console.log(data)); | ||
Build image: | ||
```bash | ||
docker build -t go-proxy-rotator . | ||
``` | ||
|
||
## Building for Production | ||
|
||
For production builds, use: | ||
|
||
Run container: | ||
```bash | ||
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o proxy-server . | ||
docker run -d \ | ||
-p 60255:1080 \ | ||
-v $(pwd)/proxies.conf:/app/proxies.conf:ro \ | ||
-v $(pwd)/users.conf:/app/users.conf:ro \ | ||
-e ENABLE_EDGE_MODE=true \ | ||
go-proxy-rotator | ||
``` | ||
|
||
## Security Notes | ||
|
||
- Always use strong passwords in `users.conf` | ||
- Consider using HTTPS/SOCKS5 proxies for sensitive traffic | ||
- The server logs minimal information for privacy | ||
|
||
## Contributing | ||
|
||
Contributions are welcome! Please feel free to submit a Pull Request. | ||
|
||
## License | ||
|
||
MIT License | ||
|
||
## Acknowledgments | ||
## Contributing | ||
|
||
Built using: | ||
- [go-socks5](https://github.com/armon/go-socks5) - SOCKS5 server implementation | ||
- Go's standard library for proxy and networking features | ||
Contributions are welcome! Please feel free to submit a Pull Request. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/armon/go-socks5" | ||
"go-proxy-rotator/internal/config" | ||
"go-proxy-rotator/internal/proxy_dialer" | ||
"go-proxy-rotator/internal/proxy_manager" | ||
"log" | ||
) | ||
|
||
func main() { | ||
// Load configuration | ||
cfg := config.NewConfig() | ||
|
||
// Load user credentials | ||
credentials, err := config.LoadUserCredentials(cfg.UsersFile) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Initialize proxy manager | ||
proxyManager := proxy_manager.NewManager(cfg.EnableEdgeMode) | ||
if err := proxyManager.LoadProxies(cfg.ProxiesFile); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Initialize proxy dialer | ||
dialer := proxy_dialer.NewProxyDialer(proxyManager) | ||
|
||
// Create SOCKS5 server configuration with authentication | ||
serverConfig := &socks5.Config{ | ||
Dial: dialer.Dial, | ||
Credentials: credentials, | ||
AuthMethods: []socks5.Authenticator{socks5.UserPassAuthenticator{ | ||
Credentials: credentials, | ||
}}, | ||
} | ||
|
||
server, err := socks5.New(serverConfig) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Printf("SOCKS5 server running on %s (Edge Mode: %v, Users: %d)\n", | ||
cfg.ListenAddr, | ||
cfg.EnableEdgeMode, | ||
len(credentials)) | ||
|
||
// Start server | ||
if err := server.ListenAndServe("tcp", cfg.ListenAddr); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
Oops, something went wrong.