Code Monkey home page Code Monkey logo

tcp-udp-proxy's Introduction

TCP-UDP-Proxy

A proxy server program written in C++ that can forward TCP or UDP packets to and from some pre-configured address. It's a transparent proxy in that remote clients only have to change their destination IP/PORT into those of the proxy, and the proxy will automatically forword packets according to pre-configured rules.

A typical usage scenario is to bypass a company firewall that blocks packets from some limited internal IP/Subnets.

It can also be used for simulating public network environment in an intranet by configuring bandwidth limit, network delay, or packet drop rate(only for UDP).

[Install] Boost Library is required. Please look into src/Makefile to find out how Boost libs are linked, and you can change the path according to your environment.

On Linux: $cd src $make

On Windows: Becasue the project is cross-platform, it can be compiled as a Visual Studio C++ project. What you have to do is to create a project and import all files under src dir, also remember to link those Boost libs listed in Makefile.

[Configuration and Usage] Refer to the comments in proxy.conf to see how to configure the forwarding rules. A typical proxy.conf looks like:

tcp 3443 180.166.47.38 3443 
tcp 1234 180.166.47.38 1234 100000
udp 6500 10.35.60.1 6500 100000 100 1000

The 1st line shows the proxy will open local tcp port 3443 to receive new connections which are to be forwarded directly to and from remote address 180.166.47.38/3443.

The 2nd line does similar functions, the difference is it also imposes a bandwidth limit of 100K/S in both directions.

The 3rd line is a rule to forward UDP packets, from local port 6500 to remote address 10.35.60.1/6500, and also in reverse direction. Additionally, it indicates a bandwidth limit of 100K/S, a delay of 100ms, and a packet drop rate of 10%, in both directions.

tcp-udp-proxy's People

Contributors

mengrao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tcp-udp-proxy's Issues

License?

I was wondering if I could use this project as the base for a Docker container I am creating.
It would be nice if you could add a license to your repository, so people know if they can use your code for open source projects.

Build error

Hi,
I've tried to compile the source, the result is:

# make
g++ -I .  -Wall -Werror -O3 -c -o ServerArgsBase.o ServerArgsBase.cpp
g++ -I .  -Wall -Werror -O3 -c -o xthread.o xthread.cpp
g++ -I .  -Wall -Werror -O3 -c -o shared_data.o shared_data.cpp
In file included from udp_proxy.h:3:0,
                 from shared_data.h:5,
                 from shared_data.cpp:1:
buffer.h: In member function ‘global::Buffer::operator bool() const’:
buffer.h:89:11: error: cannot convert ‘const boost::shared_array<unsigned char>’ to ‘bool’ in return
    return buf;
           ^~~
Makefile:44: recipe for target 'shared_data.o' failed
make: *** [shared_data.o] Error 1

What would be the problem?

Thanks,

a.

Convert from TCP to UDP

Any thoughts on making this able to proxy TCP to UDP? Trying to get packets off the wire that are TCP and covert them to UDP and forward them to a destination host, on the same port. It would be amazing if you could help.

Problem Building in Visual Studio Pro 2019

I've been trying to compile TCP-UDP-Proxy for Windows, ultimately Windows 10, but at the moment I'm trying to compile on my Windows 7 VM. I am using Visual Studio Pro 2019. After trying the latest version (1.75.0) of the Boost Library with some errors due to some deprecated members, I bounced around older versions until finding that Version 1.68.0 reduced my compile errors substantially, and of those 20 or so errors, are caused by some typedef problems in fstream.hpp. (I could be wrong, but the errors all seem to be related to fstream_fix.)

Specifically, I get the following errors to begin with:

'fstream_fix<std::basic_ifstream<char,std::char_traits<char> > >' is not a variable template
'fstream_fix<std::basic_ofstream<char,std::char_traits<char> > >' is not a variable template

This comes from the following lines in the fstream.hpp from boost

typedef basic_ifstream<char> ifstream;  
typedef basic_ofstream<char> ofstream;

Where ifstream and ofstream are indicated as being redefined in the project's xfstream.h as

#define ifstream fstream_fix<std::ifstream>
#define ofstream fstream_fix<std::ofstream>

With the definition of fstream_fix in xfstream.h as

template<class T>
struct fstream_fix
	: public T
{
	fstream_fix(){};

	template<class T1>
	fstream_fix(T1 v1){
		setlocale(LC_CTYPE, "");
		T::open(v1);
		setlocale(LC_CTYPE, 0);
	}

	template<class T1,class T2>
	fstream_fix(T1 v1,T2 v2){
		setlocale(LC_CTYPE, "");
		T::open(v1,v2);
		setlocale(LC_CTYPE, 0);
	}


	template<class T1>
	void open(T1 v1){
		setlocale(LC_CTYPE, "");
		T::open(v1);
		setlocale(LC_CTYPE, 0);
	}

	template<class T1,class T2>
	void open(T1 v1,T2 v2){
		setlocale(LC_CTYPE, "");
		T::open(v1,v2);
		setlocale(LC_CTYPE, 0);
	}
};

So I'm wondering if this is a newer/different compiler issue? Or the application itself? Or maybe just missing something like the ifstream and ofstream in fstream.hpp should be set to the std namespace. Although I tried to declare those identifiers directly, and that did not help.

Hope we can get this cleaned up.

Thanks,
Mack

Possibility of virtual ip masking

user defines a subnet over cli argument like --virtualnet=192.168.1.X
client ip 123.12.12.3 connects
proxy assigns virtual ip address from subnet template, resulting in 192.168.1.12 to the datagrams
maybe it should be detected if the ip is in use by another device...
the datagram is forwarded to server
when response is received for 192.168.1.12
the datagram destination is restored to 123.12.12.3
then it is sent back to client

Compiling Errors

Hello,
I noticed that when I try to make, it runs into multiple deprecated errors and if I try to ignore them it end up saying

g++: error: ./xrandom.o: No such file or directory
g++: error: ./tcp_proxy.o: No such file or directory
g++: error: ./faraway_proxy.o: No such file or directory
g++: error: ./args.o: No such file or directory
g++: error: ./xdaemon.o: No such file or directory
g++: error: ./udp_proxy.o: No such file or directory
g++: error: ./watch.o: No such file or directory
g++: error: ./common.o: No such file or directory
g++: error: ./xthread.o: No such file or directory
g++: error: ./ip_proxy.o: No such file or directory
g++: error: ./xmisc.o: No such file or directory
g++: error: ./ServerArgsBase.o: No such file or directory
g++: error: ./shared_data.o: No such file or directory

And I just wanted to ask if you could update your project since I would love to use it for my purposes.
Regards, Malte Stein

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.