Page 1 of 1
[SOLVED] Check to see if a port is open
Posted: Tue Aug 03, 2004 3:50 am
by Revan
Hello, im running HLStats, and im making a script that prints weither its up or not
I was thinking some thing like
Code: Select all
$stat_dameon = fsockopen("udp://127.0.0.1","27500");
if ( $stat_dameon ) {
print "Online";
} elseif ( !$stat_dameon ) {
print "Offline";
}
but it doesnt work, any ideas?
Posted: Tue Aug 03, 2004 5:20 am
by kettle_drum
Try adding the other parameters to the fsockopen.
Code: Select all
$stat_dameon = fsockopen("127.0.0.1","27500", &$err_num, &$err_msg, 30);
if ( $stat_dameon ) {
print "Online";
} elseif ( !$stat_dameon ) {
print "Offline";
}
Posted: Tue Aug 03, 2004 6:02 am
by fresh
thats awesome, you can do that stuff with PHP??
what a great friggin language

Posted: Tue Aug 03, 2004 6:29 am
by Revan
fresh wrote:thats awesome, you can do that stuff with PHP??
what a great friggin language

Yes, PHP is the best
first time working with socks
@kettle_drum
that didnt work :/
btw its a UDP port so i tryed doing
Code: Select all
<?php
$stat_dameon2 = fputs($stat_dameon,"test");
?>
but it still says its online
Posted: Tue Aug 03, 2004 6:50 am
by markl999
Posted: Tue Aug 03, 2004 12:01 pm
by Revan
Don't think so, absul suck with classes
the problem im having is fsockopen doesnt return that it connected or failed, iit returns a process ID
Posted: Tue Aug 03, 2004 3:38 pm
by hedge
check the warning about 1/4 of the way down
http://ca2.php.net/manual/en/function.fsockopen.php . I think you need to actually read something after you've got the pointer using fgets.
Posted: Tue Aug 03, 2004 4:42 pm
by Revan
In the end i used this
Code: Select all
<?php
$socket_hlstats_daemon = @socket_create(AF_INET,SOCK_DGRAM,SOL_UDP);
$stat_dameon = @socket_bind($socket_hlstats_daemon , "127.0.0.1", 27500);
if ( $stat_dameon ) {
print "Offline";
} else {
print "Online";
}
@socket_close($socket_hlstats_daemon);
?>
Gave up on fsocket
Thanks for trying guys
