PHP5 - [FSocket]Telnet server online checker [IPs from MySQL DB] [MySql Extract]
Discuss [FSocket]Telnet server online checker [IPs from MySQL DB] [MySql Extract] in the PHP Development forum on Dev Shed. [FSocket]Telnet server online checker [IPs from MySQL DB] [MySql Extract] PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
Posts: 2,879
Time spent in forums: 1 Year 2 Weeks 1 Day 2 h 43 m 20 sec
Reputation Power: 581
Perhaps you need to better explain what you are trying to accomplish. Most admins keep port 23 turned off so that is not a very reliable way to determine if a server it online.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.
Posts: 7
Time spent in forums: 1 h 14 m 46 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
Perhaps you need to better explain what you are trying to accomplish. Most admins keep port 23 turned off so that is not a very reliable way to determine if a server it online.
It will be hosted on my servers status checking my other servers so no worries about that.
I'm trying to basically extract all of the information aka 'strings' from my MySQL database then connecting to each IP from the DB.
Posts: 2,879
Time spent in forums: 1 Year 2 Weeks 1 Day 2 h 43 m 20 sec
Reputation Power: 581
Even worse. You should have port 23 off as well. Telnet is much too vulnerable to hacking. If you just want to see if the host is alive, why not use ICPM?
In any case what error message are you getting (get rid of the '@' on fopensocket) and add error checking:
Posts: 7
Time spent in forums: 1 h 14 m 46 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
Even worse. You should have port 23 off as well. Telnet is much too vulnerable to hacking. If you just want to see if the host is alive, why not use ICPM?
In any case what error message are you getting (get rid of the '@' on fopensocket) and add error checking:
Posts: 7
Time spent in forums: 1 h 14 m 46 sec
Reputation Power: 0
[QUOTE=gw1500se]You haven't really explained what is wrong yet. I based my responses on the assumption that something was wrong with the 'fsopensocket' handling.
If you are having difficulty with the database query, my first advice is to not use the depreciated MySQL extensions. Start by switching to PDO.
You need to be more explicit about the problem What is it you want and what are you getting instead?/QUOTE]
... I have to use MySQL.
All I need is to EXTRACT data from my sql database. and then connect to each line (IPs of servers will be submitted in database)
and I want it to check how many are online and print it that's it.
Posts: 2,879
Time spent in forums: 1 Year 2 Weeks 1 Day 2 h 43 m 20 sec
Reputation Power: 581
Here's a code snippet showing how I would do it using PDO. However this is untested and will need to be modified to fit your requirements, integrate into your actual code and desired output.
PHP Code:
$conn=new PDO("mysql:host=$host;dbname=$db",$user,$pass) || die ("Unable to connect to database: ".PDO::errorinfo();
$query = "SELECT * FROM boxes";
$Port=23; // note this is a number not a string "23"
foreach ($conn->query($query) as $row) {
$IP=$row['IP']; // I'm guessing what your field names are so you will need to fix it
$Check = fsockopen($IP, $Port, $errno, $errstr, .5);
if (!$Check) {
echo "$errstr<br />\n";
}
else {
echo 'Servers online: ' . $Check;
fclose($Check);
}
}
P.S. I'm not sure what you expect to be echoed but I don't think it is what you really want. $Check is just a file handle.
Last edited by gw1500se : November 15th, 2012 at 12:19 PM.
Posts: 7
Time spent in forums: 1 h 14 m 46 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
Here's a code snippet showing how I would do it using PDO. However this is untested and will need to be modified to fit your requirements, integrate into your actual code and desired output.
PHP Code:
$conn=new PDO("mysql:host=$host;dbname=$db",$user,$pass) || die ("Unable to connect to database: ".PDO::errorinfo();
$query = "SELECT * FROM boxes";
$Port=23; // note this is a number not a string "23"
foreach ($conn->query($query) as $row) {
$IP=$row['IP']; // I'm guessing what your field names are so you will need to fix it
$Check = fsockopen($IP, $Port, $errno, $errstr, .5);
if (!$Check) {
echo "$errstr<br />\n";
}
else {
echo 'Servers online: ' . $Check;
}
fclose($Check);
}
P.S. I'm not sure what you expect to be echoed but I don't think it is what you really want.