Page 1 of 1

How to detect the port using PHP?

Posted: Sat Dec 13, 2003 2:00 am
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.

Posted: Sat Dec 13, 2003 2:36 am
by infolock
you in windows? you could do something like :

echo passthru("netstat -a");

untested, but gives you an idea.

Posted: Sat Dec 13, 2003 2:57 am
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 ...

Posted: Sat Dec 13, 2003 3:42 am
by m3mn0n
Also research [php_man]fsockopen[/php_man]()

And another for PEAR:

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