By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,127 Members | 1,135 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,127 IT Pros & Developers. It's quick & easy.

TCP/IP Monitoring in .NET

P: n/a
Does anyone have a code sample of how one would "listen"
to a TCP/IP session between an application on the local
machine and a remote host.

I'm looking for code that would allow me to specify a
local IP and a local port which is already in use by
another application (outside of my control) and simply
watch the traffic.

I know there are open source packet analyzers available
that use special network drivers, use of permiscuous
network mode, etc., etc. But I'm not looking to watch
any traffic except to and from my local machine on a
known port and I am hoping that this is less complicated
and that .NET's rich netwoking classes will lend a hand.

The two biggest issues that exist are the fact that
windows sockets does not like an port/ip pair bound to
two different sockets. I can sidestep this issue by
using SetSocketOption and SocketOptionName.ReuseAddress,
but I have found that simply binding to the address is
not sufficient to create the desired effect.

Any help?
Jul 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi Randal,

You may try to see the SetSocketOption function.
But if the other application use the socket as SocketOptionName
=ExclusiveAddressUse
Then you can not use SetSocketOption to set your socket as
SocketOptionName = ReuseAddress which allows the socket to be bound to an
address that is already in use.

Did I answer your question?

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
Content-Class: urn:content-classes:message
From: "Randal" <ra****@nospam.com>
Sender: "Randal" <ra****@nospam.com>
Subject: TCP/IP Monitoring in .NET
Date: Thu, 25 Sep 2003 14:38:50 -0700
Lines: 24
Message-ID: <0b****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcODrWig9CK3fawTTni7PrRRY/Zqww==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:109938
NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
X-Tomcat-NG: microsoft.public.dotnet.general

Does anyone have a code sample of how one would "listen"
to a TCP/IP session between an application on the local
machine and a remote host.

I'm looking for code that would allow me to specify a
local IP and a local port which is already in use by
another application (outside of my control) and simply
watch the traffic.

I know there are open source packet analyzers available
that use special network drivers, use of permiscuous
network mode, etc., etc. But I'm not looking to watch
any traffic except to and from my local machine on a
known port and I am hoping that this is less complicated
and that .NET's rich netwoking classes will lend a hand.

The two biggest issues that exist are the fact that
windows sockets does not like an port/ip pair bound to
two different sockets. I can sidestep this issue by
using SetSocketOption and SocketOptionName.ReuseAddress,
but I have found that simply binding to the address is
not sufficient to create the desired effect.

Any help?


Jul 21 '05 #2

P: n/a
Randal,
Does anyone have a code sample of how one would "listen"
to a TCP/IP session between an application on the local
machine and a remote host.


Take a look at this: http://www.mentalis.org/soft/projects/pmon/

fyi: IIRC it's w2k and later only
--
Abderaware
Fine Components For .NET
Turn on, tune in, download.
zane a@t abderaware.com
Jul 21 '05 #3

P: n/a
Exactly what I was looking for! Thanks a million, Zane.
-----Original Message-----
Randal,
Does anyone have a code sample of how one would "listen"to a TCP/IP session between an application on the local
machine and a remote host.
Take a look at this:

http://www.mentalis.org/soft/projects/pmon/
fyi: IIRC it's w2k and later only
--
Abderaware
Fine Components For .NET
Turn on, tune in, download.
zane a@t abderaware.com
.

Jul 21 '05 #4

P: n/a
As noted in my post, I am already using SetSocketOption
with the ReuseAddress option, but I was looking for some
of the specifics of extracting the information, since the
underlying socket is already connected. The issue is
that Socket.Receive cannot be used without the new socket
being connected. I am trying to figure out the specifics
of making a "connection" to the connection that already
exists by the original application.
-----Original Message-----
Hi Randal,

You may try to see the SetSocketOption function.
But if the other application use the socket as SocketOptionName=ExclusiveAddressUse
Then you can not use SetSocketOption to set your socket asSocketOptionName = ReuseAddress which allows the socket to be bound to anaddress that is already in use.

Did I answer your question?

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
Content-Class: urn:content-classes:message
From: "Randal" <ra****@nospam.com>
Sender: "Randal" <ra****@nospam.com>
Subject: TCP/IP Monitoring in .NET
Date: Thu, 25 Sep 2003 14:38:50 -0700
Lines: 24
Message-ID: <0b****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcODrWig9CK3fawTTni7PrRRY/Zqww==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:109938NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
X-Tomcat-NG: microsoft.public.dotnet.general

Does anyone have a code sample of how one would "listen"to a TCP/IP session between an application on the local
machine and a remote host.

I'm looking for code that would allow me to specify a
local IP and a local port which is already in use by
another application (outside of my control) and simply
watch the traffic.

I know there are open source packet analyzers available
that use special network drivers, use of permiscuous
network mode, etc., etc. But I'm not looking to watch
any traffic except to and from my local machine on a
known port and I am hoping that this is less complicatedand that .NET's rich netwoking classes will lend a hand.

The two biggest issues that exist are the fact that
windows sockets does not like an port/ip pair bound to
two different sockets. I can sidestep this issue by
using SetSocketOption and SocketOptionName.ReuseAddress,but I have found that simply binding to the address is
not sufficient to create the desired effect.

Any help?


.

Jul 21 '05 #5

P: n/a
Randal,
Does anyone have a code sample of how one would "listen"
to a TCP/IP session between an application on the local
machine and a remote host.


Take a look at this: http://www.mentalis.org/soft/projects/pmon/

fyi: IIRC it's w2k and later only
--
Abderaware
Fine Components For .NET
Turn on, tune in, download.
zane a@t abderaware.com
Jul 21 '05 #6

P: n/a
Hi Randal,

You may try to see the SetSocketOption function. By default, when you new a
socket, it will use the ExclusiveAddressUse option,
i.e. you can not use SetSocketOption to set your socket as
SocketOptionName = ReuseAddress which allows the socket to be bound to an
address that is already in use.
To let the ReuseAddress work, you may need to set the two application all
with ReuseAddress option.
e.g.
Socket listener = new Socket(AddressFamily.InterNetwork,SocketType.Strea m,
ProtocolType.Tcp );
listener.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddr
ess,1);

But, when the latter running application running the SetSocketOption and
bind to the socket, the first running application will no longer get data.
Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
Content-Class: urn:content-classes:message
From: "Randal" <ra****@nospam.com>
Sender: "Randal" <ra****@nospam.com>
References: <0b****************************@phx.gbl> <nK**************@cpmsftngxa06.phx.gbl>Subject: RE: TCP/IP Monitoring in .NET
Date: Fri, 26 Sep 2003 14:09:55 -0700
Lines: 84
Message-ID: <1e****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcOEcojs7W6hWfK5SUSj1TgJuJCktQ==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:110074
NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
X-Tomcat-NG: microsoft.public.dotnet.general

As noted in my post, I am already using SetSocketOption
with the ReuseAddress option, but I was looking for some
of the specifics of extracting the information, since the
underlying socket is already connected. The issue is
that Socket.Receive cannot be used without the new socket
being connected. I am trying to figure out the specifics
of making a "connection" to the connection that already
exists by the original application.
-----Original Message-----
Hi Randal,

You may try to see the SetSocketOption function.
But if the other application use the socket as

SocketOptionName
=ExclusiveAddressUse
Then you can not use SetSocketOption to set your socket

as
SocketOptionName = ReuseAddress which allows the socket

to be bound to an
address that is already in use.

Did I answer your question?

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and

confers no rights.

--------------------
Content-Class: urn:content-classes:message
From: "Randal" <ra****@nospam.com>
Sender: "Randal" <ra****@nospam.com>
Subject: TCP/IP Monitoring in .NET
Date: Thu, 25 Sep 2003 14:38:50 -0700
Lines: 24
Message-ID: <0b****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcODrWig9CK3fawTTni7PrRRY/Zqww==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gblmicrosoft.public.dotnet.general:109938NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
X-Tomcat-NG: microsoft.public.dotnet.general

Does anyone have a code sample of how onewould "listen"to a TCP/IP session between an application on the local
machine and a remote host.

I'm looking for code that would allow me to specify a
local IP and a local port which is already in use by
another application (outside of my control) and simply
watch the traffic.

I know there are open source packet analyzers available
that use special network drivers, use of permiscuous
network mode, etc., etc. But I'm not looking to watch
any traffic except to and from my local machine on a
known port and I am hoping that this is lesscomplicatedand that .NET's rich netwoking classes will lend a hand.

The two biggest issues that exist are the fact that
windows sockets does not like an port/ip pair bound to
two different sockets. I can sidestep this issue by
using SetSocketOption andSocketOptionName.ReuseAddress,but I have found that simply binding to the address is
not sufficient to create the desired effect.

Any help?


.


Jul 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.