Transistor Posted April 10, 2008 Share Posted April 10, 2008 I have a PC based vision inspection system capable of sending data strings of the measurements and results (possibly in XML format - I don't know yet). I can specify an IP address and port number on the sending application. I want to capture the measurement data and log it to a database. Q1. What Linux app can I run to monitor the port - say port 4001? (This should show me the raw data so I understand what's being transmitted.) Q2. What's the best way to capture data from that port using a php script? e.g. Can I redirect port 4001 to run a particular php script every time something shows up on that port? Many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/100498-how-do-i-capture-data-sent-to-a-tcp-port-eg-port-4001/ Share on other sites More sharing options...
trq Posted April 10, 2008 Share Posted April 10, 2008 What's the best way to capture data from that port using a php script? e.g. Can I redirect port 4001 to run a particular php script every time something shows up on that port? This ought answer both questions. You can build a sockets server to listen to that port, I'm not sure php is the best solution for such a thing, but its possible. Take a look at the sockets extension. Quote Link to comment https://forums.phpfreaks.com/topic/100498-how-do-i-capture-data-sent-to-a-tcp-port-eg-port-4001/#findComment-513975 Share on other sites More sharing options...
Transistor Posted April 10, 2008 Author Share Posted April 10, 2008 Thanks, Thorpe. I've done some more reading and think that TCPDUMP might get me started. http://www.tcpdump.org/tcpdump_man.html. I'll try tcpdump 'tcp port 4001 As far as I can make out it should display all traffic in (and out) on port 4001. I've used php sockets on another small application but it was run from a CRON job. In this case I need to run a script every time traffic comes in on port 4001. I realise I can't leave a PHP script running waiting for an event. I'll see what I can come up with. Anyone else? Quote Link to comment https://forums.phpfreaks.com/topic/100498-how-do-i-capture-data-sent-to-a-tcp-port-eg-port-4001/#findComment-514269 Share on other sites More sharing options...
doni49 Posted April 11, 2008 Share Posted April 11, 2008 You could load apache and let apache listen to the port. Make your script the default web page. Quote Link to comment https://forums.phpfreaks.com/topic/100498-how-do-i-capture-data-sent-to-a-tcp-port-eg-port-4001/#findComment-514348 Share on other sites More sharing options...
Transistor Posted April 11, 2008 Author Share Posted April 11, 2008 Thanks, all. tcpdump 'tcp port 4001' works for low level stuff. If you're using it you need to limit the "count" so it will terminate after a while. Otherwise you'll have to kill the process. Seehttp://tcpdump.org Quote Link to comment https://forums.phpfreaks.com/topic/100498-how-do-i-capture-data-sent-to-a-tcp-port-eg-port-4001/#findComment-514575 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.