-
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
0 parents
commit bcb0943
Showing
12 changed files
with
1,148 additions
and
0 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,3 @@ | ||
COMPOSE_PROJECT_NAME=go-proxy-rotator | ||
DC_SOCKS_PROXY_PORT=60255 | ||
ENABLE_EDGE_MODE=true |
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,51 @@ | ||
name: Build and Push Docker image to GHCR | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: | ||
group: self-hosted | ||
#labels: | ||
# - Linux | ||
permissions: | ||
packages: write | ||
contents: read | ||
|
||
steps: | ||
# Step 1: Checkout the repository | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
# Step 2: Log in to GitHub Container Registry (GHCR) | ||
- name: Log in to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Step 3: Define dynamic image name and tag based on repo name | ||
- name: Set dynamic image name and tag | ||
id: vars | ||
run: | | ||
REPO_NAME=$(basename "${{ github.repository }}") # Extract the repository name | ||
IMAGE_NAME="ghcr.io/${{ github.repository_owner }}/$REPO_NAME" | ||
GIT_SHA="${{ github.sha }}" | ||
TAG="main-${GIT_SHA:0:7}" # Example: Use first 7 characters of commit SHA | ||
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV | ||
echo "IMAGE_TAG=$TAG" >> $GITHUB_ENV | ||
# Step 4: Build the Docker image with both tags | ||
- name: Build Docker image | ||
run: | | ||
docker build -t $IMAGE_NAME:$IMAGE_TAG -t $IMAGE_NAME:latest . | ||
# Step 5: Push both Docker image tags to GHCR | ||
- name: Push Docker image to GHCR | ||
run: | | ||
docker push $IMAGE_NAME:$IMAGE_TAG | ||
docker push $IMAGE_NAME:latest |
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,26 @@ | ||
# Binary | ||
/proxy-server | ||
|
||
# Config files with sensitive data | ||
.env | ||
#proxies.conf | ||
#users.conf | ||
|
||
# Go specific | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# IDE | ||
.idea/ | ||
.vscode/ | ||
*.swp | ||
|
||
# MacOS | ||
.DS_Store | ||
|
||
# Temp files | ||
*.log | ||
*.tmp |
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,27 @@ | ||
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 | ||
|
||
WORKDIR /build | ||
|
||
# Copy go mod and source files | ||
COPY go.mod go.sum ./ | ||
COPY *.go ./ | ||
|
||
# Download dependencies | ||
RUN go mod download | ||
|
||
# Build the application | ||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o proxy-server . | ||
|
||
# Final stage | ||
FROM scratch | ||
WORKDIR /app | ||
COPY --from=builder /build/proxy-server . | ||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,241 @@ | ||
# Go Proxy Rotator | ||
|
||
A high-performance SOCKS5 proxy server written in Go that rotates through multiple upstream proxies. Perfect for distributed scraping, API access, and general proxy needs. | ||
|
||
## 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) | ||
- Round-robin proxy rotation | ||
- Edge mode for fallback to direct connections | ||
- Multi-user support via configuration file | ||
- Docker and docker-compose support | ||
- Configurable port | ||
- Zero runtime dependencies | ||
- Comments support in configuration files | ||
- Automatic proxy failover | ||
- IPv6 support | ||
|
||
## Quick Start with Docker Compose (Recommended) | ||
|
||
1. Clone the repository: | ||
```bash | ||
git clone https://github.com/ariadata/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 | ||
``` | ||
|
||
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 | ||
``` | ||
4. Start the service: | ||
```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 | ||
``` | ||
|
||
## 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://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 | ||
# 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 | ||
``` | ||
|
||
## Edge Mode | ||
|
||
When edge mode is enabled (`ENABLE_EDGE_MODE=true`), the server will: | ||
|
||
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 | ||
```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 | ||
``` | ||
|
||
### With Python Requests | ||
```python | ||
import requests | ||
|
||
proxies = { | ||
'http': 'socks5h://user:pass@localhost:60255', | ||
'https': 'socks5h://user:pass@localhost:60255' | ||
} | ||
|
||
response = requests.get('https://api.ipify.org?format=json', proxies=proxies) | ||
print(response.json()) | ||
``` | ||
|
||
### 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); | ||
|
||
fetch('https://api.ipify.org?format=json', { agent }) | ||
.then(res => res.json()) | ||
.then(data => console.log(data)); | ||
``` | ||
|
||
## Building for Production | ||
|
||
For production builds, use: | ||
|
||
```bash | ||
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o proxy-server . | ||
``` | ||
|
||
## 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 | ||
|
||
Built using: | ||
- [go-socks5](https://github.com/armon/go-socks5) - SOCKS5 server implementation | ||
- Go's standard library for proxy and networking features |
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,20 @@ | ||
services: | ||
go-proxy-rotator: | ||
image: 'ghcr.io/ariadata/go-proxy-rotator:latest' | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
container_name: go-proxy-rotator | ||
restart: unless-stopped | ||
env_file: | ||
- .env | ||
ports: | ||
- '${DC_SOCKS_PROXY_PORT:-1080}:1080' | ||
volumes: | ||
- ./proxies.conf:/app/proxies.conf | ||
- ./users.conf:/app/users.conf | ||
healthcheck: | ||
test: [ "CMD", "nc", "-z", "localhost", "1080" ] | ||
interval: 30s | ||
timeout: 10s | ||
retries: 3 |
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 @@ | ||
module go-proxy-rotator | ||
|
||
go 1.22.5 | ||
|
||
require github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 | ||
|
||
require golang.org/x/net v0.33.0 // indirect |
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,4 @@ | ||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= | ||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= | ||
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= | ||
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= |
Oops, something went wrong.