|
Posted by Adam on 10/06/52 11:28
On Mon, 3 Oct 2005 23:08:23 +0200, Boniface Frederic wrote:
>Hello,
>
>I need to check if a user has properly open his port on his computer. He
>will call a script specifing the port he want to use and the script will
>have to check if he can open a socket on the IP:Port.
>Here is a what I have tried but it doesn't work, even if the port is
>properly open :
>
>-----------------------------Script ------------------
><?php
>ob_implicit_flush();
>
>if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0)
>{
> die("socket_create() failed : " . socket_strerror($sock) . "\n");
>}
>
>if (($ret = socket_connect($sock, $address, $port)) < 0)
>{
> die("socket_connect() failed : raison : " . socket_strerror ($ret) .
>"\n");
>}
>
>echo "connected\n";
>
>socket_close($sock);
>?>
>-------------------------End Script ---------------------
>
>Any suggestions ? Thanks in advance.
I've been messing with just this lately - see the thread "Ping+Port
Routine". It's not that old.
In short, it's a nightmare!
1) Depends on which build of PHP - whether it was compiled with socket
support.
2) OS Dependent. Many socket functions don't appear to work on a Win32
setup.
3) Contrary to what it says on the PHP bugtracker, I think many of the
socket routines still have bugs. Some even appear to have been
re-introduced in PHP5.
4) Check whether a firewall is blocking things.
5) Set up a port "sniffer" (Ethereal or suchlike) to see whether
packets are a actually leaving/arriving (though a firewall can still
block these).
6) I found that a socket sometimes gets "blocked" with an error - even
when the [code] error has been fixed. Try it with another port (that
you know is open). After a time, I've found I can re-use the original
connection. There must be a timeout somewhere.
Adam.
Navigation:
[Reply to this message]
|