Redir is a simple, lightweight, and robust multi-protocol redirector written in Go.
It allows you to redirect incoming connections on a local port to a remote IP and port, supporting multiple protocols including TCP, UDP, and HTTP, with full bidirectional support.
- 🔁 Full bidirectional support for TCP, UDP, and HTTP redirection
- ⚙️ Easy-to-use command-line interface for selecting protocols
- 🧱 Can be imported as a library into any Go project
- 🚨 Robust error handling and panic safety
- 📦 Clean and dependency-free (except for
github.com/fatih/colorfor color logging)
To use this package in your project:
go get github.com/luftwaffe66/redirectorYou can use Redir by importing it into your Go application and initializing the redirector with the desired configuration.
package main
import (
"log"
"github.com/luftwaffe66/redirector"
)
func main() {
opts := redirector.RedirectOptions{
ListenPort: "8080", // Local port to listen on
DestinationIP: "192.168.1.100", // Remote destination IP
DestinationPort: "9090", // Remote port to forward to
Verbose: true, // Show info logs
}
if err := redirector.StartRedirector(opts); err != nil {
log.Fatalf("Redirector failed: %v", err)
}
}The RedirectOptions struct is used to configure the redirector. Here's the full reference:
type RedirectOptions struct {
ListenPort string // Local port to bind and accept incoming connections
DestinationIP string // Remote target IP address
DestinationPort string // Remote target port
Verbose bool // Whether to log connection events
}When StartRedirector() is called, it:
- Listens on the specified local port
- Accepts incoming connections for the selected protocol (TCP, UDP, or HTTP)
- Forwards the connection to the specified remote IP and port
- Maintains bidirectional data flow (client ↔ server)
- Logs only important messages unless Verbose is set to true
Currently, the following protocols are supported:
- TCP: Redirects bidirectional TCP traffic
- UDP: Redirects UDP packets, supporting basic data forwarding
- HTTP: Redirects HTTP requests to the target destination
MIT License
See LICENSE for details.