|
|
|
|
![]() ![]() |
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! This post has been edited by NeOniX: Jun 17 2006, 05:43 PM |
|
|
|
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? |
|
|
|
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 |
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. 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...' (note: tried out in trap17 hosting and works) This post has been edited by NeOniX: Jul 7 2006, 06:35 AM |
|
|
|
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...! |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 20th July 2008 - 05:35 PM |