Monitoring a port on web server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tony599
Forum Newbie
Posts: 1
Joined: Wed Feb 23, 2011 2:46 am

Monitoring a port on web server

Post 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
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Monitoring a port on web server

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Monitoring a port on web server

Post by VladSun »

What are you trying to do? Some kind of authorization?
Looks like a port-knocking technique to me :)
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply