难度:Low
代码解析
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = $_REQUEST[ 'ip' ];
// Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
// Feedback for the end user
echo "<pre>{$cmd}</pre>";
}
?>
1.stristr() PHP stristr() 函数
stristr() 函数搜索字符串在另一字符串中的第一次出现。
语法:stristr(string,search,before_search)
参数 | 描述 |
---|---|
string | 必需。规定被搜索的字符串。 |
search | 必需。规定要搜索的字符串。 如果该参数是数字,则搜索匹配该数字对应的 ASCII 值的字符。 |
before_search | 可选。默认值为 "false" 的布尔值。 如果设置为 "true",它将返回 search 参数第一次出现之前的字符串部分。 |
返回字符串的剩余部分(从匹配点)。如果未找到所搜索的字符串,则返回 FALSE。
2.php_uname() PHP中php_uname的用法详解
返回运行 PHP 的系统的有关信息。
参数
mode 是单个字符,用于定义要返回什么信息:
'a':此为默认。包含序列 "s n r v m" 里的所有模式。
's':操作系统名称。例如: FreeBSD。
'n':主机名。例如ÿ