1 Star 0 Fork 44

星辰无限 / socks_server

forked from Jack.arain / proxy 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSL-1.0

一个使用现代c++实现的socks4/5协议的实现

使用c++20协程,支持socks4/socks4a/socks5的server/client实现.

使用示例程序:


#include "socks/logging.hpp"

#include "socks/socks_server.hpp"
#include "socks/socks_client.hpp"

#include "socks/use_awaitable.hpp"

#include <boost/asio/io_context.hpp>
#include <boost/asio/co_spawn.hpp>
#include <boost/asio/detached.hpp>

#include <memory>

namespace net = boost::asio;
using net::ip::tcp;
using namespace socks;

using server_ptr = std::shared_ptr<socks_server>;

net::awaitable<void> start_socks_server(server_ptr& server)
{
	tcp::endpoint socks_listen(
		net::ip::address::from_string("0.0.0.0"),
		1080);

	socks_server_option opt;
	opt.usrdid_ = "jack";
	opt.passwd_ = "1111";

	auto executor = co_await net::this_coro::executor;
	server =
		std::make_shared<socks_server>(
			executor, socks_listen, opt);
	server->open();

	co_return;
}

net::awaitable<void> start_socks_client()
{
	auto executor = co_await net::this_coro::executor;
	tcp::socket s(executor);

	tcp::endpoint server_addr(
		net::ip::address::from_string("127.0.0.1"),
		1080);

	// tcp socket connect to socks server.
	boost::system::error_code ec;
	co_await s.async_connect(server_addr, asio_util::use_awaitable[ec]);
	if (ec)
	{
		LOG_WARN << "client connect to server: " << ec.message();
		co_return;
	}

	// handshake and tell to socks server target.
	socks::socks_client_option opt;

	opt.target_host = "www.baidu.com";
	opt.target_port = 80;

	opt.proxy_hostname = true;
	opt.username = "jack";
	opt.password = "1111";

	co_await socks::async_socks_handshake(s, opt, asio_util::use_awaitable[ec]);
	if (ec)
	{
		LOG_WARN << "client handshake to server: " << ec.message();
		co_return;
	}

	LOG_DBG << "completed socks handshake.";

	// Next, do some http stuff with socket...

	co_return;
}

int main()
{
	net::io_context ioc(1);
	server_ptr server;

	co_spawn(ioc, start_socks_server(server), net::detached);
	co_spawn(ioc, start_socks_client(), net::detached);

	ioc.run();
	return 0;
}

very easy to use!!!

Boost Software License - Version 1.0 - August 17th, 2003 Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一个socks4/5的代理服务器实现。 展开 收起
BSL-1.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/linys668/socks_server.git
git@gitee.com:linys668/socks_server.git
linys668
socks_server
socks_server
master

搜索帮助