Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[PHP] Pinging A Site

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Localhost
I post too much
Reputation: 0

Joined: 28 Apr 2007
Posts: 3402

PostPosted: Wed Jun 04, 2008 5:00 pm    Post subject: [PHP] Pinging A Site Reply with quote

Code:
<?php

   $serverHost = "www.cheatengine.org";
   $serverPort = 80;

   function createSocket()
   {
      $socket = @socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
      @socket_set_option( $socket, SOL_SOCKET, SO_RCVTIMEO, array("sec"=>10, "usec"=>100) );
      if( !$socket ){
         die( 'Failed to create a new socket.' );
      }else{
         return $socket;
      }
   }
   
   function CheckIfRunning()
   {
      global $serverHost, $serverPort;
      $socket = createSocket();
      $connection = @socket_connect( $socket, gethostbyname( $serverHost ), $serverPort );
      if( !$connection )
         echo( 'Server is not online.' );
      else
         echo( 'Server is online!' );
      @socket_close( $socket );
   }
?>

<HTML>
<HEAD>
 <TITLE>Server Check</TITLE>
</HEAD>
<BODY>
 <p> <?php CheckIfRunning(); ?> </p>
</BODY>
</HTML>

This is not my own work.

How can this be done, but with multiple hosts and ports?
Back to top
View user's profile Send private message MSN Messenger
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Wed Jun 04, 2008 5:01 pm    Post subject: Reply with quote

Use an array for the serverHost variable and loop through it.
Back to top
View user's profile Send private message MSN Messenger
Localhost
I post too much
Reputation: 0

Joined: 28 Apr 2007
Posts: 3402

PostPosted: Wed Jun 04, 2008 5:22 pm    Post subject: Reply with quote

how do i "loop" through it.

Also... i think it will be the same serverHost, but different IPs... Thanks Smile
Back to top
View user's profile Send private message MSN Messenger
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Wed Jun 04, 2008 5:28 pm    Post subject: Reply with quote

Code:
for ( $i = 0 ; i < $numberOfHosts ; $i++ )  {
         // Ping serverHost[i]
}


I don't know PHP so I cant really help you any more. The commented bit is where you do your ping on $serverHost[i].
Back to top
View user's profile Send private message MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Wed Jun 04, 2008 5:28 pm    Post subject: Reply with quote

Code:
$site_array = array( "www.cheatengine.org", "www.google.com" );

for( $i=0; $i<count($site_array); $i++ )
{
 // Adjust ping code inside here.
}


A small example of what would be needed.

If you are wondering the above code is mine. I wrote it for another person in another topic.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Localhost
I post too much
Reputation: 0

Joined: 28 Apr 2007
Posts: 3402

PostPosted: Wed Jun 04, 2008 5:33 pm    Post subject: Reply with quote

ah. I am very confused now. I have to ping multiple ports on the same IP.

Thanks Smile
Back to top
View user's profile Send private message MSN Messenger
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Wed Jun 04, 2008 5:35 pm    Post subject: Reply with quote

Well its the same thing but you replace the host names with the ports.
Back to top
View user's profile Send private message MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Wed Jun 04, 2008 5:35 pm    Post subject: Reply with quote

If you need that, then use 1 static address, and array the ports instead. Then adjust the code to use the for loop variable for the port array instead. Should be easy enough to fix.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Wed Jun 04, 2008 5:38 pm    Post subject: Reply with quote

Wiccaan wrote:
If you need that, then use 1 static address, and array the ports instead. Then adjust the code to use the for loop variable for the port array instead. Should be easy enough to fix.


And if he wants to do a range of ports he can just use a variable and ++ it in a loop until it hits the last port.
Back to top
View user's profile Send private message MSN Messenger
Localhost
I post too much
Reputation: 0

Joined: 28 Apr 2007
Posts: 3402

PostPosted: Wed Jun 04, 2008 5:41 pm    Post subject: Reply with quote

Code:

<?php

   $serverHost = "www.google.com";
   $serverPort = array(80,8080);

   for( $i=0; $i<count($serverPort); $i++ )
   {

   function createSocket()
   {
      $socket = @socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
      @socket_set_option( $socket, SOL_SOCKET, SO_RCVTIMEO, array("sec"=>10, "usec"=>100) );
      if( !$socket ){
         die( 'Failed to create a new socket.' );
      }else{
         return $socket;
      }
   }
   
   function CheckIfRunning()
   {
      global $serverHost, $serverPort;
      $socket = createSocket();
      $connection = @socket_connect( $socket, gethostbyname( $serverHost ), $serverPort );
      if( !$connection )
         echo( 'Server is not online.' );
      else
         echo( 'Server is online!' );
      @socket_close( $socket );
   }
}
?>

<HTML>
<HEAD>
 <TITLE>Server Check</TITLE>
</HEAD>
<BODY>
 <p> <?php CheckIfRunning(); ?> </p>
</BODY>
</HTML>

So like that?
Also how do i display it so it is like:

80: is open
8080: is closed
etc etc
Back to top
View user's profile Send private message MSN Messenger
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Wed Jun 04, 2008 5:53 pm    Post subject: Reply with quote

Code:
$serverHost = "www.google.com";

$socket = @socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
@socket_set_option( $socket, SOL_SOCKET, SO_RCVTIMEO, array("sec"=>10, "usec"=>100) );

for( $i = 80 ; $i < 8080 ; $i++ )
{
     $connection = @socket_connect( $socket, gethostbyname( $serverHost ), $i );
     if( !$connection )
         echo( 'Port ' + $i ' + is not open!' );
      else
         echo( 'Port ' + $i + ' is open!' );
}


I don't know PHP so correct any errors and change stuff. It might work Laughing
Back to top
View user's profile Send private message MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Wed Jun 04, 2008 9:22 pm    Post subject: Reply with quote

Heres a simple port scanner. Adjust the timeouts to make it faster if needed:

Code:
<?php

   //
   // Site Variables
   //
   $site_link = "www.google.com";
   $site_port = array( 80, 90 );

   //
   // createSocket()
   //
   //  Creates a new connection socket object. Note, you need
   //  to close this socket yourself after creating it!
   //
   function createSocket()
   {
      $socket = @socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
      @socket_set_option( $socket, SOL_SOCKET, SO_RCVTIMEO, array("sec"=>10, "usec"=>0) );
      @socket_set_option( $socket, SOL_SOCKET, SO_SNDTIMEO, array("sec"=>10, "usec"=>0) );
      if( !$socket ){
         die( 'Failed to create a new socket.\n' );
      }else{
         return $socket;
      }
   }

   //
   // checkPorts()
   //
   //  Scans the given site for open ports based on the port array
   //  above. The scan starts with the first port and scans upto
   //  the second port in the array.
   //
   function checkPorts()
   {
      global $site_link, $site_port;

      echo( 'Site: ' . $site_link . " " . gethostbyname( $site_link ) . "<br />\n" );

      for( $i = $site_port[0]; $i <= $site_port[1]; $i++ )
      {
         // Create Socket Instance
         $socket = createSocket();

         // Make Connection
         $connection = @socket_connect( $socket, gethostbyname( $site_link ), $i );

         // Output Result
         if( !$connection ){
            echo( 'Port: ' . $i . " is currently closed.<br /> \n" );
         }else{
            echo( 'Port: ' . $i . " is currently open.<br /> \n" );
         }

         // Close The Open Socket
         @socket_close( $socket );
      }
   }
?>

<HTML>
<HEAD>
 <TITLE>Port Check</TITLE>
</HEAD>
<BODY>
 <p> <?php checkPorts(); ?> </p>
</BODY>
</HTML>

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites