repositorypackage
0.0.0-20241203125445-00a4a4e5ac65
Repository: https://github.com/oxplot/slapup.git
Documentation: pkg.go.dev
# README
slapup
slapup
is a flexible TCP port forwarding tool with process management capabilities. It allows you to map local ports to remote ports while providing additional features like running commands on connection and managing background processes.
Features
- Multiple port forwarding configurations
- Automatic process management based on active connections
- Custom command execution on new connections
- Flexible connection mapping formats
- Connection status logging
- Graceful process termination
Installation
go install github.com/oxplot/slapup@latest
Usage
slapup [options] -- command [args...]
Options
-l
: Specify connection mapping in one of these formats:localport:remoteport
(uses 127.0.0.1 for both hosts)localport:remotehost:remoteport
localhost:localport:remotehost:remoteport
-on-conn
: Command to run when a connection is established%h
: Replaced with the local host%p
: Replaced with the local port
Connection Mapping Examples
# Map local port 8080 to remote port 80 on localhost
slapup -l 8080:80 -- ./myapp
# Map local port 3000 to remote port 8080 on example.com
slapup -l 3000:example.com:8080 -- ./myapp
# Map specific interface and port to remote service
slapup -l 192.168.1.10:3000:api.example.com:8080 -- ./myapp
# Multiple port mappings
slapup -l 3000:8080 -l 3001:8081 -- ./myapp
Process Management
slapup
manages the specified command as follows:
- Starts the command when the first connection is established
- Keeps the command running while there are active connections
- Gracefully terminates the command after all connections close (with a 10-second delay)
- Automatically restarts the command if it crashes while connections are active
Running Commands on Connection
Use -on-conn
to execute a command when a new connection is established:
slapup -l 8080:80 -on-conn "echo New connection from %h:%p" -- ./myapp
Error Handling
- Logs connection failures and retry attempts
- Graceful shutdown on interrupt signal (Ctrl+C)
- Automatic process restart on crashes
- Connection timeout after 10 seconds of failed attempts