Coder Social home page Coder Social logo

caiyesd / mnh Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hzyitc/mnh

0.0 0.0 1.0 103 KB

A NAT hole punching tool that allows peers directly connect to your NATed server without client. 一个对端不需要客户端就可以直接连接的NAT打洞工具

License: BSD 3-Clause "New" or "Revised" License

Go 97.74% Shell 2.26%

mnh's Introduction

mnh

GitHub release

README | 中文文档

!!! Note: mnh is currently in development, the APIs and command line options may not be backward compatible !!!

Introduction

mnh is a tool that makes exposing a port behind NAT possible.

mnh will produce an ip:port pair for your NATed server which can be used for public access.

--------------------------------
| Help Server (NOT behind NAT) |  <------(query for ip:port pair)-------------
--------------------------------                                             |
        ^                                                                    |
        |                                                                    |
        |       ---------(Use some way to send ip:port pair)-------------    |
        |       |                                                       | or |
        |       |                                                       ↓    |
------------------------                  ~~~~~~~~~~~~                ----------
| Service (behind NAT) |    <--------     { Internet }   <----------  | Guests |
------------------------                  ~~~~~~~~~~~~                ----------

Usage

Pre-requests

  • Your server's network type should be Full-cone NAT.

    If you don't known what it means, no worries, just continue.

  • If your server is behind a firewall or a household router, you probably need to enable UPnP or do a port forwarding to your server on your router since they may block all incoming traffics.

Setup up a Help server

Please check mnh_server.

Only mnhv1 protocol is currently supported, more protocols will be added in the future, such as STUN.

Run mnh

Usage:
  mnh {tcp|udp} --server <server> [flags]

Flags:
  -s, --server string    Help server address(Example: "server.com", "server.com:6641")
                           If only specify hostname, it will try SRV resolve.
                           If SRV failed, it will use default port(6641).
  -i, --id string        A unique id to identify your machine

  -m, --mode string      Run mode.
                           TCP support: demoWeb proxy (default "demoWeb")
                           UDP support: demoEcho proxy (default "demoEcho")
  -p, --port int         The local hole port which incoming traffics access to
  -t, --service string   Target service address. Only need in proxy mode (default "127.0.0.1:80")

  -r, --routerForward    A comma-split list which will be used sequentially to request router to do port forwarding (default: "upnp,notice")
                           upnp: UPnP protocol
                           notice: Will notice you to do port forwarding manually
                           none: Do port forwarding manually

  -x, --event-hook       Execute command when event triggered:
                           escape:
                             %%: percent sign
                             %e: Event: connecting fail success disconnected
                             %m: Error message
                             %p: Local hole port
                             %a: Hole addr

  -h, --help             help for mnh

Example:

Run a Web server for test:

./mnh tcp --server server.com --id test

Run a UDP Echo server for test:

./mnh udp --server server.com --id udpEcho --mode demoEcho

Expose a local web server:

./mnh tcp --server server.com --id web --mode proxy --service 127.0.0.1:80

mnh will attempt to request router to do port forwarding with upnp protocol by default.

If failed, it will show a notice.

You can disable these two functions by set --routerForward none, make sure you have set up port forwarding correctly. (See Pre-requests)

./mnh tcp --server server.com --id web --mode proxy --service 127.0.0.1:80 --port 8888 --routerForward none

mnh's People

Contributors

hzyitc avatar provissy avatar

Forkers

ccf-yang

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.