PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 15th, 2012, 10:44 AM
Bawt Bawt is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 7 Bawt Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 h 14 m 46 sec
Reputation Power: 0
PHP5 - [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.

Reply With Quote
  #2  
Old November 15th, 2012, 10:53 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,879 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
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.

Reply With Quote
  #3  
Old November 15th, 2012, 10:54 AM
Bawt Bawt is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 7 Bawt Negative: is most likely a SPAMMER and a traitor to the cause. 
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.

Reply With Quote
  #4  
Old November 15th, 2012, 11:02 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,879 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
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:
PHP Code:
 $Check fsockopen($IP$Port$errno$errstr.5);
if (!
$Check) {
   echo 
"$errstr<br />\n";
}
else {
   echo 
'Servers online: ' $Check;


Reply With Quote
  #5  
Old November 15th, 2012, 11:04 AM
Bawt Bawt is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 7 Bawt Negative: is most likely a SPAMMER and a traitor to the cause. 
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:
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?

Reply With Quote
  #6  
Old November 15th, 2012, 11:21 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,879 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 1 Day 2 h 43 m 20 sec
Reputation Power: 581
Yes, I was giving you code for just the 'fsopensocket' snippet.

Reply With Quote
  #7  
Old November 15th, 2012, 11:29 AM
Bawt Bawt is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 7 Bawt Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 h 14 m 46 sec
Reputation Power: 0
Quote:
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

Reply With Quote
  #8  
Old November 15th, 2012, 11:46 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,879 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 1 Day 2 h 43 m 20 sec
Reputation Power: 581
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?

Reply With Quote
  #9  
Old November 15th, 2012, 11:53 AM
Bawt Bawt is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 7 Bawt Negative: is most likely a SPAMMER and a traitor to the cause. 
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.

Reply With Quote
  #10  
Old November 15th, 2012, 12:13 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,879 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
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.

Reply With Quote
  #11  
Old November 15th, 2012, 12:17 PM
Bawt Bawt is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 7 Bawt Negative: is most likely a SPAMMER and a traitor to the cause. 
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.

Please convert it so it'll work with mysql.

Reply With Quote
  #12  
Old November 15th, 2012, 12:20 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,879 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 1 Day 2 h 43 m 20 sec
Reputation Power: 581
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.

Reply With Quote
  #13  
Old November 15th, 2012, 12:49 PM
Bawt Bawt is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 7 Bawt Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 h 14 m 46 sec
Reputation Power: 0
Quote:
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?

Reply With Quote
  #14  
Old November 15th, 2012, 12:51 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,879 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 1 Day 2 h 43 m 20 sec
Reputation Power: 581
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?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP5 - [FSocket]Telnet server online checker [IPs from MySQL DB] [MySql Extract]

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap