Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Checking For Open Ports From Php, If you want to check the status of a server at a specific port you can
NeOniX
post Jun 17 2006, 05:22 AM
Post #1


Newbie [Level 1]
*

Group: Members
Posts: 22
Joined: 17-June 06
From: Nebuchadnezzar, dock 6, Zion
Member No.: 25,271



Some days ago, i needed to check ports of a server from a webpage, for advising of its status.
I simply used a great php code that's fsockopen. I'll explain it in the following example:

(Imagine a file called 'checkports.php', containing the next)
CODE
<?
$address =" trap17.com"; //Here you can specify the address you want to check ports
$port = "80"; //Here you can specify the port you want to check from $address
$checkport = fsockopen($address, $port, $errnum, $errstr, 2); //The 2 is the time of ping in secs

//Here down you can put what to do when the port is closed
if(!$checkport){
       echo "The port ".$port." from ".$address." seems to be closed.";  //Only will echo that msg
}else{

//And here, what you want to do when the port is open
       echo "The port ".$port." from ".$address." seems to be open."; //The msg echoed if port is open
}
?>


Well, that's all, but you can do with it a lot of interesting stuff, i.e., you put that on a host with PHP, and check if another host is up, and it is, redirect to... etc.

Enjoy! tongue.gif

This post has been edited by NeOniX: Jun 17 2006, 05:43 PM
Go to the top of the page
 
+Quote Post
uiop
post Jun 17 2006, 05:49 PM
Post #2


Premium Member
********

Group: Members
Posts: 193
Joined: 20-December 05
Member No.: 15,962



Awsome code! Thanks a ton for it! I'm not really sure what I can use it for, but it sounds cool!

Do you need any special server permissions to run this script? Will it run on all servers?
Go to the top of the page
 
+Quote Post
NeOniX
post Jun 17 2006, 07:07 PM
Post #3


Newbie [Level 1]
*

Group: Members
Posts: 22
Joined: 17-June 06
From: Nebuchadnezzar, dock 6, Zion
Member No.: 25,271



QUOTE(uiop @ Jun 17 2006, 07:49 PM) *

Do you need any special server permissions to run this script? Will it run on all servers?


Lol er... well dunno if all servers let u using fsockopen(), cuz i actually use my own server, so i suppose it depends of the host. You could post a topic on a forum askin' 4 that. biggrin.gif
Anyway, yesterday i try to use on a free hosting server with PHP, and it gave me back an error like 'Due to security reasons...' sad.gif

(note: tried out in trap17 hosting and works)

This post has been edited by NeOniX: Jul 7 2006, 06:35 AM
Go to the top of the page
 
+Quote Post
masterio
post Aug 27 2006, 11:14 AM
Post #4


Member [Level 1]
****

Group: Members
Posts: 50
Joined: 25-August 06
Member No.: 28,897




Well, i didnt know if trap17.com disable some function like fsockopen(), shell_exec(), passthru(), and many other PHP function to communicate with filesystem. I think it may be disable for security reason...! smile.gif. By the way fsockopen() is usefull for grabbing page, etc besid file_get_contents() function.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Checking The Web Site Speed(10)
  2. Image Preloader With Progress Bar Status(22)
  3. Checking Your Php Version(1)
  4. How To Setup Your Own Dns (domain Name Server)(1)
  5. Server Status(12)
  6. Set Os X Server 10.3 Dhcp To Filter Desks(0)
  7. A Nice Mysql Server Check(4)
  8. Run Your Own Mail / Radio Server(24)
  9. Pinging Servers(16)
  10. Checking Dns Settings For Website(2)
  11. Making A Dynamic Page On Blogspot(5)
  12. Starting Or Stopping Apache And Mysql Server Via Batch File(0)
  13. How To Create Counter-strike 1.6 Server In Console Mode(5)
  14. How To Make Your Own Counter Strike Source Dedicated Server!(2)


 



- Lo-Fi Version Time is now: 20th July 2008 - 05:35 PM