Skip to content

ischenyu/neter

Repository files navigation

Neter

Go Version License

A powerful network utility tool written in Go, supporting TCP/UDP/Unix socket communication with server, client, and proxy modes.

中文文档

Features

  • Multiple Modes: Server, Client, and Proxy modes
  • Protocol Support: TCP, UDP, and Unix domain sockets
  • Connection Retry: Configurable retry count with infinite retry support
  • Connection Timeout: Configurable timeout for connections
  • Output File: Save received data to a file
  • Latency Monitoring: Real-time latency display option
  • Graceful Shutdown: Clean shutdown on SIGINT/SIGTERM signals
  • Thread-Safe: Concurrent-safe file writing with sync writer
  • Error Handling: Comprehensive error handling and logging

Installation

From AUR (Arch Linux)

yay -S neter
# or
paru -S neter

From Source

git clone https://github.com/ischenyu/neter.git
cd neter
go build -o neter .

Using Go Install

go install github.com/ischenyu/neter@latest

Usage

Basic Syntax

neter [flags]

Flags

Flag Description Default
-m Mode: server, client, proxy client
-t Protocol: tcp, udp, unix tcp
-h Host (or path for unix socket) -
-p Port -
-o Output file path -
-r Retry count (0=no retry, -1=infinite) 0
-T Connection timeout 5s
-proxy Proxy destination (host:port), proxy mode only -
-latency Show latency to stdout false

Examples

Server Mode

Start a TCP server on port 8080:

neter -m server -h 0.0.0.0 -p 8080

Start a UDP server:

neter -m server -t udp -h 0.0.0.0 -p 8080

Start a Unix socket server:

neter -m server -t unix -h /tmp/neter.sock

Client Mode

Connect to a TCP server:

neter -m client -h 127.0.0.1 -p 8080

Connect with retry (infinite):

neter -m client -h 127.0.0.1 -p 8080 -r -1

Connect with timeout and retry:

neter -m client -h 127.0.0.1 -p 8080 -r 5 -T 10s

Save output to file:

neter -m client -h 127.0.0.1 -p 8080 -o output.log

Show latency:

neter -m client -h 127.0.0.1 -p 8080 -latency

Proxy Mode

Start a proxy listening on port 9090 and forwarding to 127.0.0.1:8080:

neter -m proxy -h 0.0.0.0 -p 9090 -proxy 127.0.0.1:8080

Building from Source

Prerequisites

  • Go 1.26 or later

Build

# Clone the repository
git clone https://github.com/ischenyu/neter.git
cd neter

# Build
go build -o neter .

# Run tests
go test -v -race ./...

# Build with optimizations
go build -ldflags="-s -w" -o neter .

Architecture

Connection Handling

  • TCP: Standard stream-based connections with proper half-close support
  • UDP: Connectionless datagram handling with per-client tracking
  • Unix: Domain socket support for local IPC

Data Flow

Client/Server → handleConnection() → stdout + optional file output
                    ↑
              stdin → network

Proxy Architecture

Client → Proxy Listener → Target Server
           ↓                    ↑
         localConn ←→ remoteConn (bidirectional forwarding)

Error Handling

All close operations are properly handled with error logging:

  • Listener close errors
  • Connection close errors
  • File write errors
  • Read/Write operation errors

Testing

Run the test suite:

# Run all tests
go test -v ./...

# Run with race detection
go test -v -race ./...

# Run specific test
go test -v -run TestTCP ./...

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Built with Go's standard library
  • Inspired by netcat and similar tools

About

A powerful network utility tool written in Go, supporting TCP/UDP/Unix socket communication with server, client, and proxy modes.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors