How to detect the port using PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Shawn_cn
Forum Newbie
Posts: 1
Joined: Sat Dec 13, 2003 2:00 am

How to detect the port using PHP?

Post by Shawn_cn »

i want to show my server status on my Web Page as the following:

Server Type Port Status
Web Server 80 On
Ftp Server 21 On
...
etc.

So what's the main function of PHP to do this?or how to do this?
thank you.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

you in windows? you could do something like :

echo passthru("netstat -a");

untested, but gives you an idea.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

Code: Select all

$tmp = exec("netstat -a", $results); 
foreach ($results as $row)
	{ echo $row . "<br>"; }
echo "done";
if you know specific ports you want, try
-p TCP instead of -a ...
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Also research [php_man]fsockopen[/php_man]()

And another for PEAR:

http://pear.php.net/manual/en/package.n ... ckport.php
Post Reply