473,385 Members | 1,341 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,385 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 7821
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...
1
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.