473,804 Members | 3,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check for activity on TCP port

Can someone give a quick example of how to check for activity on a TCP
port? For example, I'd like to watch and listen for activity on port
80. Once activity is detected, I'd like an event to be triggered.

Thanks in advanced.

May 12 '07 #1
4 11291
Hello Sir,

See this C# sniffer http://www.c-sharpcorner.com/UploadF...ifferInCS.aspx
---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

SCCan someone give a quick example of how to check for activity on a
SCTCP port? For example, I'd like to watch and listen for activity on
SCport 80. Once activity is detected, I'd like an event to be
SCtriggered.
SC>
SCThanks in advanced.
SC>
May 12 '07 #2
On May 12, 2:24 pm, Michael Nemtsev <nemt...@msn.co mwrote:
Hello Sir,

See this C# snifferhttp://www.c-sharpcorner.com/UploadFile/leonidmolochniy/SimpleSniffer.. .

---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog:http://spaces.live.com/laflour
Team blog:http://devkids.blogspot.com/

Thanks for the quick response. That example was not the most
complete / easy to follow example :(

Let me clarify my request a little. I can get an array of tcp
listeners via the following code:

IPGlobalPropert ies.GetIPGlobal Properties();
IPEndPoint[] endPoints = properties.GetA ctiveTcpListene rs();

I'm looking for an event that will fire once a tcp port moves from the
listening status to established status. I want this to run as a
service so I don't want it to chew up cycles constantly checking for a
specific port to move form listening to established that's why I ask
for an event. Basically I want to execute some code once the port
moves from listening to established, and then run some clean up code
once it moves from established back to listening.

May 12 '07 #3
On Sat, 12 May 2007 14:44:31 -0700, Sir C4 <Va*******@gmai l.comwrote:
[...]
I'm looking for an event that will fire once a tcp port moves from the
listening status to established status.
You should probably learn more about TCP first.

There's no such thing as a TCP port moving "from listening status to
established status". An entirely new connection, with the "establishe d"
status, is created when an application with a "listening" TCP port accepts
the connection. But the "listening" TCP port remains, and is still
listening for new connections.
I want this to run as a
service so I don't want it to chew up cycles constantly checking for a
specific port to move form listening to established that's why I ask
for an event.
Short of sniffing the network traffic and watching for TCP connections
being created, I'm not aware of any way to do what you want. Not directly
anyway.

One thing you could do is poll the TCP status and check for new
"establishe d" connections on the same port as a "listening" port.
Obviously you wouldn't want to poll too often (maybe once every 5 or 10
seconds), but this would be one way to do it.

The obvious problem with this is that a connection could be closed and
then reopened between the time you've polled, or opened and closed for
that matter. You won't get guaranteed notification of network connection
changes this way, but it might be close enough for your purposes. Depends
on what you're actually doing.
Basically I want to execute some code once the port
moves from listening to established, and then run some clean up code
once it moves from established back to listening.
If you think it might be useful for getting better advice, you might
consider being more specific about the "clean up code". I'm having a hard
time imagining what one process would be able to usefully "clean up" in
response to some other process connecting or disconnecting TCP
connections. There's a small possibility that there's an entirely
different approach to accomplish what you're trying to do, but no one can
offer that information if they don't know what the end goal here is.

Pete
May 13 '07 #4
On May 12, 6:53 pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
wrote:
On Sat, 12 May 2007 14:44:31 -0700, Sir C4 <Vagyok...@gmai l.comwrote:
[...]
I'm looking for an event that will fire once a tcp port moves from the
listening status to established status.

You should probably learn more about TCP first.

There's no such thing as a TCP port moving "from listening status to
established status". An entirely new connection, with the "establishe d"
status, is created when an application with a "listening" TCP port accepts
the connection. But the "listening" TCP port remains, and is still
listening for new connections.
I want this to run as a
service so I don't want it to chew up cycles constantly checking for a
specific port to move form listening to established that's why I ask
for an event.

Short of sniffing the network traffic and watching for TCP connections
being created, I'm not aware of any way to do what you want. Not directly
anyway.

One thing you could do is poll the TCP status and check for new
"establishe d" connections on the same port as a "listening" port.
Obviously you wouldn't want to poll too often (maybe once every 5 or 10
seconds), but this would be one way to do it.

The obvious problem with this is that a connection could be closed and
then reopened between the time you've polled, or opened and closed for
that matter. You won't get guaranteed notification of network connection
changes this way, but it might be close enough for your purposes. Depends
on what you're actually doing.
Basically I want to execute some code once the port
moves from listening to established, and then run some clean up code
once it moves from established back to listening.

If you think it might be useful for getting better advice, you might
consider being more specific about the "clean up code". I'm having a hard
time imagining what one process would be able to usefully "clean up" in
response to some other process connecting or disconnecting TCP
connections. There's a small possibility that there's an entirely
different approach to accomplish what you're trying to do, but no one can
offer that information if they don't know what the end goal here is.

Pete
Pete,

Thanks for your insight. Basically I'm using VNC for remote
administration. Vista's new aero glass slows down the screen refresh
rate. Basically I want to watch for the VNC connection, when it's
detected, disable the aero experience, and when the connection is
closed, turn aero back on.

I think your explination will work out just fine.

May 13 '07 #5

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

Similar topics

5
19734
by: Alex Polite | last post by:
If I try to bind a socket to a port that's already in use I get this error "error socket.error: (98, 'Address already in use')" Is there anyway to check in advance if a port i already taken? alex --
4
2597
by: eight02645999 | last post by:
hi in python, how do one query a port to see whether it's up or not? thanks
1
1594
by: Scott Lezberg \(Deltek\) | last post by:
Is it possible to check for a port (such as port 8000) in use using VB .NET? If so, is there any sample code around. Thanks in advance. Scott
4
2927
by: ValK | last post by:
Hello All, I need to write VB.NET application as Windows Service with the following functions: - the Windows Service shall be able to scan and receive data via serial port - the received data from serial port to be saved in the text files. Is anybody can advice the proper way to do it? Thank you VK
1
6327
by: Marty Cruise | last post by:
I understand how easy it is to use the my.computer.network.ping command, but is it as easy to check for a response on a given port? How can I check for a response for port x at 123.456.789?
2
8102
by: NoOne | last post by:
Hi everybody! I'm want to check if a certain port is opened or closed. now I'm using try-catch to connect to the port. if it fails, it meas that the port is closed. The problem is that this method is extremely inefficient! anyone has a better idea on how to do this kind of verification? Thanks!
1
18552
usafshah
by: usafshah | last post by:
i have installed sql server 2000 and set default port 1433. but i ca'nt access from outside ..i have given access to sql server machine from outside ip . but i guess something is wrong the port configuration, cause when i check it through netstat (with all parameters) but is not listening on port 1433.
4
3429
by: BSM | last post by:
I have created one Web Service in VS 2005 Team Edition. In the Website Creation Template, I chose "HTTP". When I run the application, the URL was like this http://localhost:1245/WebServ1/Service.asmx When I try to include this WebService in another app, I was in the situation to include the Port number. Then only it works. Othewise it doesn't sense the web service.
3
11639
by: naveen.sabapathy | last post by:
Hi, I am trying to use virtual serial ports to develop/test my serial communication program. Running in to trouble... I am using com0com to create the virtual ports. The virtual ports seem to be working fine when I test it with Hyperterminal . I am using the example program that comes with pyserial, as below. --------------- import serial
4
4322
by: bukharifaran | last post by:
I have a code that checks if UDP port 5060 is open or not. But now i want to Check if the same port is Bussy or not.. i want to make a billing system using Asterisk SIP server and SJ Phone on Lan Network. for this purpose when i open my SJ phone and run the code which can check port is open or not? it shows me that port 5060 and 5061 is open, altough i did't make a call yet. i want to know that when i make a call and called person attend...
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9132
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.