FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Checking whether a users port is open?

 


Dougie1
I found this script from utorrent: http://www.utorrent.com/testport.php?port=222 which checks if a port is open and was wondering how it worked so I tried to recreate it:

<?php
$ip
= $_SERVER['REMOTE_ADDR'];
$ip = "udp://$ip";
$fp = fsockopen($ip, 222, $errno, $errstr, 30);
if (!
$fp) {
echo
"$ip<br>Not Open";
} else {
echo
"$ip<br>Open";
}
?>

But it does not work as it seems to always say open. What am I doing wrong? Is there another way to do this?
SonLight
I would recommend you display the status information, $errno and $errstr, along with $fp. Apparently, $fp is getting set to something besides null. You may also want to put in a close command (shouldn't hurt anything except your computer's feelings if it's not actually open). You may also want to try this on friendly users, and warn them they may get a message from their firewall if you do make it a public page. If this is to set up a legitimate communication, probably a message "testing to see if the hypercomm port is open on your machine" might be sufficient.
Dougie1
error no comes out with 0 I think and the other comes out with nothing no matter whether the port is open or closed. I don't know what I am doing wrong.

Anyone?
simplyw00x
From http://us2.php.net/fsockopen:
Quote:
Warning

UDP sockets will sometimes appear to have opened without an error, even if the remote host is unreachable. The error will only become apparent when you read or write data to/from the socket. The reason for this is because UDP is a "connectionless" protocol, which means that the operating system does not try to establish a link for the socket until it actually needs to send or receive data.


So are you sure that the IP address is being formed correctly?
gerpg
Try this link...

http://au3.php.net/fsockopen
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.