How to forward all internet connection to another machine - sockets

I want to forward all my tcp and udp connection from one of my port and pass them to another machine. Do you have any ideal ?

There is no general solution for all OSes (of courses).
A simple Google search gives you:
http://www.linuxforums.org/forum/debian-linux/148854-forward-all-network-traffic-another-server.html

Related

Is it possible to create a proxy server for any application?

I've been trying to create a proxy server to analyze TCP packages sent between my computer and a game server.
Now I know that you can do this kind of stuff with Wireshark, but I want to understand the logic of it and how the connections are made.
My main question is that I don't know where to start from. I have the server IP and port from Process Explorer and have the basic socket programming knowledge in python, but as I said, I don't know what to code.
Am I supposed to write a socket that hijacks the incoming TCP connection and forward it to my localhost? but then how would my client send data to server?
As you can see, I'm a bit lost, and I would be very happy if someone could put me in a correct path (what should I research?).
Thank you in advance.
I think there is a useful tools can help you: iptables and netfilter. Using this, you can hijacks the incoming TCP connection and forward it to your localhost easily.

Bound Local Port for SignalR Connection

Is there any way to determine which Local Port was used by the Client (C#) to Establish a connection to a SignalR Hub? I have looked at properties of both the HubCallerContext and HubConnection, but it does not seem to be available.
The short answer the question: yes, using netstat or similar you can look at all the connections your client initiated to the SignalR. There you can identify the TCP source port number.
If for some reason you want to get this from inside the application you can either try to find your way via Get underlying tcp connection from HttpWebRequest/Response
or by following this answer.

How to find the port number in ubuntu 12.04?

I need to write my first socket program involving TCP connections. In the program I have created there is a client and server, both of which are the machine I am coding on.However,it requires that I pass the port number as a command line argument. How do I accomplish this?
The answer is simple : Make sure your server and your client agree on the port to use. As long as the port is available and can be used, set up the connected so that the client and server use that same port.
Here's a link that explain the different ranges available for TCP and UDP ports.
As an exemple, the port 3074 is used by microsoft for its Xbox live service. Making an application using this port might interfere with the service.
The port used will be defined either in a configuration file or hard-coded in the source code of both the server and the client. You should easily be able to find it with a quick look at the code or the directory which contains the application.

What does it mean to connect to a certain port?

For example, when you make an ssh connection, you are connected to port 22. What happens then? On a very high level brief overview, I know that if port 22 is open on the other end and if you can authenticate to it as a certain user, then you get a shell on that machine.
But I don't understand how ports tie into this model of services and connections to different services from remote machines? Why is there a need for so many specific ports running specific services? And what exactly happens when you try to connect to a port?
I hope this question isn't too confusing due to my naive understanding. Thanks.
Imagine your server as a house with 65536 doors. If you want to visit family "HTTP", you go to door 80. If you were to visit family "SMTP", you would visit door no. 25.
Technically, a port is just one of multiple possible endpoints for outgoing/incomming connections. Many of the port numbers are assigned to certain services by convention.
Opening/establishing a connection means (when the transport protocol is TCP, which are most of the “classical” services like HTTP, SMTP, etc.) that you are performing a TCP handshake. With UDP (used for things like streaming and VoIP), there's no handshake.
Unless you want to understand the deeper voodoo of IP networks, you could just say, that's about it. Nothing overly special.
TCP-IP ports on your machine are essentially a mechanism to get messages to the right endpoints.
Each of the possible 65536 ports (16 total bits) fall under certain categories as designated by the Internet Assigned Numbers Authority (IANA).
But I don't understand how ports tie into this model of services and
connections to different services from remote machines? Why is there a
need for so many specific ports running specific services?
...
And what exactly happens when you try to connect to a port?
Think of it this way: How many applications on your computer communicate with other machines? Web browser, e-mail client, SSH client, online games, etc. Not to mention all of the stuff running under the hood.
Now think: how many physical ports do you have on your machine? Most desktop machines have one. Occasionally two or three. If a single application had to take complete control over your network interface nothing else would be able to use it! So TCP ports are a way of turning 1 connection into 65536 connections.
For example, when you make an ssh connection, you are connected to
port 22. What happens then?
Think of it like sending a package. Your SSH client in front of you needs to send information to a process running on the other machine. So you supply the destination address in the form of "user#[ip or hostname]" (so that it knows which machine on the network to send it to), and "port 22" (so it gets to the right application running on the machine). Your application then packs up a TCP parcel and stamps a destination and a return address and sends it to the network.
The network finds the destination computer and delivers the package. So now it's at the right machine, but it still needs to get to the right application. What do you think would happen if your SSH packet got delivered to an e-mail client? That's what the port number is for. It effectively tells your computer's local TCP mailman where to make the final delivery. Then the application does whatever it needs to with the data (such as verify authentication) and sends a response packet using your machine's return address. The back and forth continues as long as the connection is active.
Hope that helps. :)
The port is meant to allow applications on TCP/IP to exchange data. Each machine on the internet has one single address which is its IP. The port allows different applications on one machine to send and receive data with multiple servers on the network/internet. Common application like ftp and http servers communicate on default ports like 21 and 80 unless network administrators change those default ports for security reasons

How to establish a TCP/IP connection without opening ports?

I never figured this one out and I've been programming for years. How do P2P programs like chat programs or torrent programs manage to create connections between two peers without peers opening any ports? I know I haven't opened up a port for Skype yet I can send and receive large files to and from my friends, and I'm pretty sure all those gigabytes don't go through Skype servers. Or do they?
What about torrenting? I can upload data to peers and I haven't opened any ports either.
I'm pretty sure the answer will be language-nonspecific, but in case I'm wrong, I code mostly in C++. Thanks in advance.
You only need to "open a port" for inbound connections. One peer will open a listening port, then instruct the other peer to connect to it. If the connection fails, the peers will usually swap roles and try again. If the connection still fails, then either the transfer is aborted, or a server relay is used if feisable.
For each listening peer, if the port is behind a router/firewall, the peer can either programmably instruct the router/firewall to open a port for forwarding inbound connections to the peer (some routers support uPNP for that, and some firewalls have their own API), or the peer can try using various "hole punching" techniques to trick the router/firewall into opening a forwarding port (some routers/firewalls are not susceptible to this).
Read this for more details: How Skype & Co. get round firewalls