#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0

    [FSocket]Telnet server online checker [IPs from MySQL DB] [MySql Extract]


    Hello, well I'm having a little trouble on how I will do this.

    current code:
    PHP Code:
    <?
    include "config.php";
    mysql_connect($host,$user,$pass);
    mysql_select_db($db);
    $query mysql_query("SELECT * FROM `boxes`");
    $boxes mysql_fetch_assoc($query)
    $IP extract($boxes);
    $Port "23";
    $Check = @fsockopen($IP$Port$errno$errstr.5);
    echo 
    'Servers online: ' $Check;
    ?>
    Basically I want it to connect & check if per IP in my MySQL DB is online via telnet [port 23].

    It will be in this formation:
    1.1.1.1
    1.2.3.4
    1.3.3.7

    etc etc.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,233
    Rep Power
    593
    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.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0
    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.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,233
    Rep Power
    593
    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:
    PHP Code:
    $Check fsockopen($IP$Port$errno$errstr.5);
    if (!
    $Check) {
       echo 
    "$errstr<br />\n";
    }
    else {
       echo 
    'Servers online: ' $Check;

    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0
    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:
    PHP Code:
    $Check fsockopen($IP$Port$errno$errstr.5);
    if (!
    $Check) {
       echo 
    "$errstr<br />\n";
    }
    else {
       echo 
    'Servers online: ' $Check;

    That's I guess, but uh I still need the MySQL extracting stuff right?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,233
    Rep Power
    593
    Yes, I was giving you code for just the 'fsopensocket' snippet.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0
    Originally Posted by gw1500se
    Yes, I was giving you code for just the 'fsopensocket' snippet.
    Could you help me with the other bit, that's the most important to me :P
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,233
    Rep Power
    593
    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?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep 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.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,233
    Rep Power
    593
    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.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0
    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.
    Please convert it so it'll work with mysql.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,233
    Rep Power
    593
    Sorry, I don't use depreciated functions. Why would you want to? I've also edited in a couple of refinements to my original code.

    Edit: I may have misunderstood your request. What I wrote DOES work with MySQL.
    Last edited by gw1500se; November 15th, 2012 at 12:39 PM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0
    Originally Posted by gw1500se
    Sorry, I don't use depreciated functions. Why would you want to? I've also edited in a couple of refinements to my original code.

    Edit: I may have misunderstood your request. What I wrote DOES work with MySQL.
    Please implement it into my code as I'm requiring config.php which has all of the $host $user $pass etc.

    Comments on this post

    • ptr2void disagrees : How about learning PHP?
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,233
    Rep Power
    593
    Just precede my code with the include. This is basic stuff. I am getting the impression you need to read through a tutorial on PHP.

    Comments on this post

    • ptr2void agrees : Demanding little bastard,eh?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo