• Lucid Dreaming - Dream Views




    Results 1 to 7 of 7
    1. #1
      The 'stache TweaK's Avatar
      Join Date
      Jul 2006
      Location
      The Netherlands
      Posts
      1,979
      Likes
      12
      PHP Port Prober

      This is just a simple little script, but it has proven it's usefulness over and over to me. I thought you might want to find this useful as well!

      Code:
      <?php
      $IPAddress = "127.0.0.1";
      $Port = "80";
      
      if($fp=fsockopen($IPAddress,$Port,$ERROR_NO,$ERROR_STR,(float)0.5)) 
      {
      ****echo "<font color=\"green\">Online</font>";
      ****fclose($fp);
      }
      else
      {
      ****echo "<font color=\"red\">Offline</font>";
      }
      ?>
      What does this do? It checks if the script can open a connection to the specified IP on the specified port and if it can, it will say Online, and if not.. Take a guess.

      It will be able to make a connection if the port is open (thus it's useful as a port prober) and if there is an application to accept the connection (webserver, FTP server, SSH server, peer-to-peer client/server, etc).

      Soooooooo. I guess that's it. Oh, configuring it. It's pretty easy, just change 127.0.0.1 to whatever IP or domainname or whatever you want, and 80 to the port you want it to connect to.
      For webservers, the default port is 80. FTP is 21. Torrent is 6881-688x I think.
      Yeah. Good luck.

      Disclaimer: This application might or might not be useful to you. If it is abused somehow (I can't think of any way, but if), don't sue me. Really, please don't. It'll cost me a lot of money, and I love my money.

    2. #2
      Wanderer Merlock's Avatar
      Join Date
      Sep 2005
      Gender
      Location
      On a journey
      Posts
      2,039
      Likes
      4
      As far as I recall, since PHP5, the socket module isn't included by default so even for something as simple as this (since I doubt someone thoroughly experienced in PHP would need this >.>), it's best to check php.ini for the needed module includes being uncommented.

    3. #3
      The 'stache TweaK's Avatar
      Join Date
      Jul 2006
      Location
      The Netherlands
      Posts
      1,979
      Likes
      12
      Everywhere I've tested it, it worked; and no additional modules were put on by me. Then again, it might've been the webhosting company that turned on the modules.

      No, an experienced PHPer would not need this. It's just a nifty little tool, which I use myself to check if my torrent ports are open, for example.

    4. #4
      Member Kaniaz's Avatar
      Join Date
      Jan 2004
      Gender
      Location
      England
      Posts
      5,441
      Likes
      9
      It's just a nifty little tool, which I use myself to check if my torrent ports are open, for example.[/b]
      Nmap?

    5. #5
      The 'stache TweaK's Avatar
      Join Date
      Jul 2006
      Location
      The Netherlands
      Posts
      1,979
      Likes
      12
      ...I hate you.

    6. #6
      Wanderer Merlock's Avatar
      Join Date
      Sep 2005
      Gender
      Location
      On a journey
      Posts
      2,039
      Likes
      4
      Quote Originally Posted by TweaK View Post
      Everywhere I've tested it, it worked; and no additional modules were put on by me. Then again, it might've been the webhosting company that turned on the modules.
      [/b]
      Exactly as I mean: just in case it doesn't work for someone, it's best to check if the socket module is loaded or not (since, once again, it's disabled by default in PHP5).

      Also, curious, is there some reason for typecasting float onto the timeout when the default type for that parameter is float as it is? Some bug fix or what not?

    7. #7
      The 'stache TweaK's Avatar
      Join Date
      Jul 2006
      Location
      The Netherlands
      Posts
      1,979
      Likes
      12
      I don't know if it can be called a bug fix, but without the float typecasting it wouldn't work for me on my demonation.net webserver.

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •