Page 1 of 1

Monitoring a port on web server

Posted: Wed Feb 23, 2011 4:03 am
by tony599
Hi

I need to continuously monitor a port (nominated in the range 7000-8999) on a web server using PHP and capture the traffic on the port to a MySQL database. It's the capture part that's proving frustrating...

The incoming data on that port can come from several IP addresses but is always sent to the same port on the server. The data messages are discrete, between 60 and 1999 bytes in length and are ASCII. They come between 2 and 30 secs apart. So far I've successfully managed to connect to one of the remote machines via fsockopen and tried various ways of fetching it directly without much success.

I really need to just monitor the port on the server itself though without connecting to a remote host (since I don't necessarily know what IP the messages are originating from) but I'm not sure that is possible unless socket_create is the way to go? Eventually, I also need to send a coded Ack to each message once validated as they are resent if not Acked so missing one is not a major problem.

Thanks in advance for any code or helpful suggestions.

TCN

Re: Monitoring a port on web server

Posted: Wed Feb 23, 2011 10:44 am
by Jonah Bron
Yes, fsockopen is the wrong function. You need the socket_* functions.

http://php.net/sockets

There are tutorials out there for setting listening to a port with the socket functions. Here's one:

http://www.devshed.com/c/a/PHP/Socket-P ... -With-PHP/

In fact, I've been working on a library for this very thing. Stay tuned and I'll get you a link.

Re: Monitoring a port on web server

Posted: Thu Feb 24, 2011 3:16 am
by VladSun
What are you trying to do? Some kind of authorization?
Looks like a port-knocking technique to me :)