How do I see if an established socket is stuck on a server that's expecting input?
Posted
by Parker
on Stack Overflow
See other posts from Stack Overflow
or by Parker
Published on 2010-06-05T06:34:54Z
Indexed on
2010/06/05
6:42 UTC
Read the original article
Hit count: 210
I have a script that scans ports for open proxy servers. Problem is if it encounters a login program (specifically telnet) then it hangs there forever since it doesn't know what to do and eventually the server closes the connection.
The simple solution would be to create a bunch of cases. If telnet, do this. If SSH, do that. If something else, blah blah blah. I'd like an umbrella solution since the script is not a high priority for me.
The script, as it is now, is available at http://parkrrr.net/socks/scan.phps
On a small scale (the page maybe averages 15 hits/day) it's fine but on a larger scale I'd be worried about a lot of open zombie sockets.
Swapping the !$strpos doesn't work since servers can return more information than what you requested (headers, ads, etc).
Only accepting a fixed number of bytes (as opposed to appending until EOF, which it does now) from the $fgets also does not seem to work. I am sure this is where it gets stuck: while (!feof($fp)) { $data.=fgets($fp,512); }
But what can I do? Any other suggestions/warnings would also be welcomed.
© Stack Overflow or respective owner