Giter Club home page Giter Club logo

nfw's Introduction

介绍

nfw是用c++11和boost::asio编写的网络转发工具。

nfw非常适合用来学习c++11和boost::asio,因为它很小,功能又简单明了。

nfw非常小,总共12个文件,共1176行(其中和安全有关的代码为500行左右),每行代码不超过80个字符,每个函数(不包括main函数)不超过20行。

用法

就从使用案例开始吧。

二个环境,家中和公司。

家中,一个路由器,有公网ip,ip为1.1.1.1,一台内网电脑。 在路由器上做了映射,公网端口12345映射到内网电脑的12345端口。 在内网电脑上运行着ssh服务,服务端口为22。

在家中的内网电脑上运行

nfw_server 0.0.0.0 12345 --user tom qazxswedc --entry ssh 127.0.0.1 22
# 0.0.0.0 12345 是监听地址和监听端口
# --user tom qazxswedc 是用户名和用户密钥
# --entry ssh 127.0.0.1 22 是转发

这个命令的意思是,在12345端口上,如果有个标记为tom的新连接进来,就用对应的密钥去验证它,验证通过后,如果它还有个ssh的标记,就转发到本机的22端口。

公司,一台内网电脑,可上网。

在公司的内网电脑上运行

nfw_client 1.1.1.1 12345 tom qazxswedc --entry 0.0.0.0 22 ssh
# 1.1.1.1 12345 是连接到家中内网电脑的地址和端口
# tom qazxswedc 是用户名和用户密钥
# --entry 0.0.0.0 22 ssh 是转发

这个命令的意思是,在公司内网电脑上开启一个新服务,服务端口为22,当该服务有一个新的连接进来,就标记它为ssh,然后通过用户信息和连接信息转发到家中的内网电脑。

接下来,在公司内网电脑上用ssh客户端连接本机的22端口,就如同连到家中内网电脑的ssh服务。

如果你想机器启动时后台运行程序,如果是linux,一般在启动文件比如rc.local加入命令行即可,别忘了命令行结尾要加上“&”,如果你的linux用的是systemd,那么做个简单的service文件即可。在windows上,也很简单,有个sc工具,能够以服务方式运行普通程序。

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.