<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// 判断传参是否为空
//isset() 函数用于检测变量是否已设置并且非 NULL。
$target = trim($_REQUEST[ 'ip' ]);
// 定义$target =(接收 [字符串] )
// trim() 函数移除字符串两侧的空白字符
$substitutions = array(
'&' => '',
';' => '',
'| ' => '',
'-' => '',
'$' => '',
'(' => '',
')' => '',
'`' => '',
'||' => '',
);
// 创建一个数据表
$target = str_replace( array_keys( $substitutions ), $substitutions, $target );
// 将输入的值与数组的键进行对比相同替换为空
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// 判断操作系统 (stristr区分大小写)
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
//根据系统版本进行ping命令(因为Windows系统不区分大小写linux区分大小写)
echo "<pre>{$cmd}</pre>";
}
//输出ping结果,(<pre>留空格和换行符)。