473,320 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Capture and redirect TCP traffic

Hi all,

Does anybody know if it is possible with VB.NET to capture and redirect
traffic that flows through a particular port? i.e. the app either
listens or watches port 1234 for outgoing traffic. It then captures or
copies all the traffic and simalteanously send it out of port 4321.

Another possible example: telnet sends info out on port 23. I want
that information captured and sent out in real-time (or almost) of port
80. And likewise, as info flows into port 80, my app sends it to port
23. Perhaps the telnet would be "telnet localhost 80" and my app is
already configured as "whatever arrives/leaves port 23, copy it and
transmit on port 80."

Sort of like bridging two ports together. Am I making it clear?

Thanks in advance.

Nov 23 '05 #1
9 7816
OK, so it seems that no-one can help with this. :-( I am not giving
up though, and if I get any results I'll post here on this thread.
Does anybody have any suggestions to get me started on this? Any ideas
of where to look, who to ask or ideas of the fundamentals required that
i'd need to link with etc etc?

All help is appreciated!

Dec 12 '05 #2
one other thing. i think that the solution that I am looking to write
would function in a similar way (if not identical perhaps) to how the
port forwarding works on a router. except that this all works on the
local machine. So as the traffic goes out, my app forwards (or
redirects) that traffic out through port 80

Dec 12 '05 #3
Yes, this is not that hard actually. Look into the System.Net namespace and
look at things like TcpListeners, Network Streams and BinaryWriters.

That's what I can give you quickly (just about to head into a meeting), if
you need more details let me know.

"Hugh Janus" <my*************@hotmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi all,

Does anybody know if it is possible with VB.NET to capture and redirect
traffic that flows through a particular port? i.e. the app either
listens or watches port 1234 for outgoing traffic. It then captures or
copies all the traffic and simalteanously send it out of port 4321.

Another possible example: telnet sends info out on port 23. I want
that information captured and sent out in real-time (or almost) of port
80. And likewise, as info flows into port 80, my app sends it to port
23. Perhaps the telnet would be "telnet localhost 80" and my app is
already configured as "whatever arrives/leaves port 23, copy it and
transmit on port 80."

Sort of like bridging two ports together. Am I making it clear?

Thanks in advance.

Dec 13 '05 #4

Ray Cassick (Home) wrote:
Yes, this is not that hard actually. Look into the System.Net namespace and
look at things like TcpListeners, Network Streams and BinaryWriters.


Hi Ray, thanks for your response! You have me intreged now. I have
been looking at these classes and am not really sure where to start.
Is there any more help you can give me?

Thanks.

Dec 13 '05 #5
p.s. That should say "intrigued" not "intreged".

Dec 13 '05 #6
Hmmm, ok this might throw a wrinkle into things a bit. It sounded like you
wanted to build something like a NAT proxy or something, but since you want
to run this process on the same machine that might take some doing.

(BEWARE - Below is off the cuff, might be broken, might have syntax errors
code examples)

It is simple to write a function that listens on a port:

Dim mSideAListenerPort As Int32
Dim mSideAListener As TcpListener
Dim mSideAClient As TcpClient
Dim mSideAIp As IPAddress
Dim mSideANetworkStream As NetworkStream
Dim mSideAReader As BinaryReader
Dim mSideAWriter As BinaryWriter

mSideAIp = IPAddress.Parse("192.168.0.1")
mSideAListener = New TcpListener(mSideAIp, 23)
mSideAListener.Start()
mSideAClient = New TcpClient

mSideAClient = mSideAListener.AcceptTcpClient 'Listens for a client to
connect to it

mSideANetworkStream = mSideAClient.GetStream

mSideAReader = New BinaryReader(mSideANetworkStream)
mSideAWriter = New BinaryWriter(mSideANetworkStream)

Then create another function to make an outbound connection:

Dim mSideBServerPort As Int32
Dim mSideBClient As TcpClient
Dim mSideBIp As IPAddress
Dim mSideBNetworkStream As NetworkStream
Dim mSideBWriter As BinaryWriter
Dim mSideBReader As BinaryReader

mSideBIp = IPAddress.Parse("192.168.0.2")

mSideBClient = New TcpClient
mSideBClient.Connect(mSideBIp, 8000)

mSideBNetworkStream = mSideBClient.GetStream

mSideBReader = New BinaryReader(mSideBNetworkStream)
mSideBWriter = New BinaryWriter(mSideBNetworkStream)

Then use the Binary Readers and Writers (in the correct order) to read from
the input and write that data to the output:

While Connected 'In one thread

mSideBWriter.Write(mSideAReader.Read)

Loop

While Connected 'In another thread

mSideAWriter.Write(mSideBReader.Read)

Loop

Of course you would need to do the cross reading and writing in different
threads because they need to happen at the same time and you will need to
make sure that you keep your readers and writers matched up otherwise you
will be crossing data.

The problem is that you want to run this on the same machine. I am not sure
how you would accomplish this to be honest. This might really take something
lower level to grab network packets before they get to the interface and
then send them on to the interface on a different port number. Something
that plugs into the IP stack. This is not something that I think you can
develop in .NET because I don't think it would be doable with managed code
at that level.

You could try this out on a second machine and see if you could get it
working then just figure out how to shoehorn it into the same machine. Keep
in mind that the one thing that keeps the processes of routers (relatively)
simple is that they are separate machines with their own destination
addresses and operate at a much lower level on the stack than this.

Also keep in mind that this example would only really cover TCP, no UDP
streams, they would have to be taken care of differently because they are a
different protocol.

Good luck. Hope I helped put this into perspective a bit.

"Hugh Janus" <my*************@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
one other thing. i think that the solution that I am looking to write
would function in a similar way (if not identical perhaps) to how the
port forwarding works on a router. except that this all works on the
local machine. So as the traffic goes out, my app forwards (or
redirects) that traffic out through port 80

Dec 14 '05 #7
Oh, and since this thread is getting a bit old and might fall off your news
reader feel free to email me if you need to. I help out where I can.

"Hugh Janus" <my*************@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
one other thing. i think that the solution that I am looking to write
would function in a similar way (if not identical perhaps) to how the
port forwarding works on a router. except that this all works on the
local machine. So as the traffic goes out, my app forwards (or
redirects) that traffic out through port 80

Dec 14 '05 #8
Ray, thanks for all this. It is fantastic. I am going to work with it
for a few days and then let you know the results. You are right, it is
best to contact you via email as this thread is pretty old now.

Thanks a lot.

Dec 14 '05 #9
to learn everything there is to know about forwarding ports in a
router visit:
www.portforward.com

On 12 Dec 2005 06:27:18 -0800, "Hugh Janus"
<my*************@hotmail.com> wrote:
one other thing. i think that the solution that I am looking to write
would function in a similar way (if not identical perhaps) to how the
port forwarding works on a router. except that this all works on the
local machine. So as the traffic goes out, my app forwards (or
redirects) that traffic out through port 80


Jan 10 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jonathan | last post by:
Hi, I want to ask something. Say I have a homepage oldhomepage.com Then I have a new homepage called newhomepage.com Now, I set up a redirection in oldhomepage.com this.location =...
2
by: Daniel | last post by:
how to detect who redirects traffic to a aspx page? is this info passed along in request object or can sites anonymously redirect traffic to other sites?
4
by: Mariano Drago | last post by:
Hi there! Im been googling all the day, but i can't find a clue about how to do what i need... So, I need to write a win32 application that "trace" or "log" or "capture" all outgoing HTTP traffic...
3
by: Nuevo | last post by:
I am looking for some method to capture, into a variable, the entire URL of an http request and redirect to SSL. For example, if a user opens a browser and typed in ...
4
by: mike.biang | last post by:
I have an ASP page that is using an XMLHTTP object to request various pages from my server. I keep a single session throughout the XMLHTTP requests by bassing the ASPSESSIONID cookie through the...
1
by: Jeck621 | last post by:
I like to create a custom code to make custom redirect. For example, I like this URL to be the redirect URL http://testme.now/test to be redirected to http://nowtesting.com. Actuall the /test folder...
2
by: Derrick | last post by:
Can anyone suggest a tool (if one exists) to capture IIS traffic and be able to "replay" that traffic? We are in the process of moving from sql2k to sql2005. What I would like to do is take a...
4
by: DGS | last post by:
Hi guys, Not a developer, but an admin so please pardon my ignorance. I have an issue that I was hoping to get help with. What I need is for the front page of my site to capture the URL that...
2
by: =?ISO-8859-1?Q?Fran=E7ois_de_Dardel?= | last post by:
I am not sure if this is the proper forum, but I always found very helpful information here and I would like to have the advice of experts. Just before new year (end Dec 2006), my internet...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.