[英]PHP checking remote server port and count connections
我已經制作了一個PHP來檢查本地的開放端口並計算連接的多少連接並打印它。 它在本地很好用,但是一旦我想遠程檢查(我的網絡服務器在差異服務器上),它就無法獲得結果。 遠程服務器是服務器2012,端口80關閉。 下面是代碼。
$handle = fopen("Includes/online.txt", "r");
$contents = fread($handle, filesize("Includes/online.txt"));
fclose($handle);
$contents = explode("\n", $contents);
//print_r($contents);
if (!$contents || (time() - $contents[1]) > $ocs) {
$command = "netstat -p TCP -n";
exec($command,$status);
//$status = PsExecute($command);
//print_r($status);
$status = array_slice($status, 5);
$connections = array();
foreach ($status as $stat => $s) {
$c = preg_split('/ /', $s, -1, PREG_SPLIT_NO_EMPTY);
if ($c[3] == 'ESTABLISHED') {
$ipp = preg_split('/:/', $c[1], -1, PREG_SPLIT_NO_EMPTY);
$ripp = preg_split('/:/', $c[2], -1, PREG_SPLIT_NO_EMPTY);
for ($i=0; $i < 6; $i++ ){
if ($ipp[1] == $config['server'][$i]['port']) {
$connections[] = array('type'=>$c[0],'ip'=>$ipp[0],'port'=>$ipp[1],'rip'=>$ripp[0],'rport'=>$ripp[1],'con'=>$c[3]);
}
}
}
}
$con = (!count($connections) ? 0 : count($connections)) ."\n". time();
if ($fp = fopen('Includes/online.txt', 'w')) {
fwrite ($fp, $con);
}
$con = array('online' => count($connections));
} else {
$con = array('online' => $contents[0]);
}
//print_r($status);
以下是連接信息。
$config['server'] = array(array('ip'=>'ipxxx',
'port'=>10201),array('ip'=>'ipxxx',
'port'=>10202),array('ip'=>'ipxxx',
'port'=>10203),array('ip'=>'ipxxx',
'port'=>10204),array('ip'=>'ipxxx',
'port'=>10205),array('ip'=>'ipxxx', 'port'=>10208));
$ocs = "20";//in seconds it checks
代碼的目的是在差異服務器(服務器2012)遠程檢查開放端口並計算總連接數並打印它。 我未能遠程做到這一點。 我需要在SQL服務器端口旁邊打開任何端口,以便PHP成功連接到服務器嗎? MSSQL已連接,我沒有任何問題。
對我而言,目前還不清楚你要求的是什么。
要檢查SQL-Server上的活動TCP / IP連接,可以使用存儲過程sp_who2
或此查詢:
select * from sys.sysprocesses where net_library like 'TCP/IP%'
SQL-Server具有默認的TCP / IP端口1433.必須在服務器端啟用TCP / IP協議。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.