Hi there
I'm new, so my apologies if this is in the wrong area.
I'd like to post the online/offline status of a hub on a website, but haven't been able to find any information on how to do it. I believe they can do it on hublist.org, but I haven't gotten a reply from anyone there.
My site is written in php, and all I need to have returned is a y/n value and I can take it from there. If anyone has anything written, I would really appreciate the help or being pointed in the right direction.
Thanks,
Nate
[edit: moved -Xan]
Hub Status on a Website
Moderator: Moderators
hm.. I couldn't get socket_select to work :-/
so here is the ugly version..
make sure you have socket support in your php install (see phpinfo();)
so here is the ugly version..
Code: Select all
function testhub($addr, $port = 411, $timeout = 2) {
$s = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)
or die(socket_strerror(socket_last_error()));
socket_set_nonblock($s)
or die(socket_strerror(socket_last_error()));
@socket_connect($s, $addr, $port);
for($i = 0; $i < $timeout * 2; ++$i) {
if($buf = @socket_read($s, 6))
if($buf == '$Lock ')
return true;
else
return false;
usleep(500000);
}
return false;
}
if(testhub("wza", 1418))
echo "ONLINE";
else
echo "OFFLINE";
http://dc.selwerd.nl/hublist.xml.bz2
http://www.b.ali.btinternet.co.uk/DCPlusPlus/index.html (TheParanoidOne's DC++ Guide)
http://www.dslreports.com/faq/dc (BSOD2600's Direct Connect FAQ)
http://www.b.ali.btinternet.co.uk/DCPlusPlus/index.html (TheParanoidOne's DC++ Guide)
http://www.dslreports.com/faq/dc (BSOD2600's Direct Connect FAQ)
... or alternately the prettier
Code: Select all
function testhub2($addr, $port = 411, $timeout = 2.0) {
if(!($f = fsockopen($addr, $port, &$errno, &$errstr, $timeout)))
return false;
if($buf = fgets($f, 6))
if($buf == '$Lock ')
return true;
return false;
}
http://dc.selwerd.nl/hublist.xml.bz2
http://www.b.ali.btinternet.co.uk/DCPlusPlus/index.html (TheParanoidOne's DC++ Guide)
http://www.dslreports.com/faq/dc (BSOD2600's Direct Connect FAQ)
http://www.b.ali.btinternet.co.uk/DCPlusPlus/index.html (TheParanoidOne's DC++ Guide)
http://www.dslreports.com/faq/dc (BSOD2600's Direct Connect FAQ)