我有以下功能,到目前为止我没有工作.我想ping一个IP地址,然后回显IP是否存在.
function pingAddress($ip){
$pingresult = shell_exec("start /b ping $ip -n 1");
$dead = "Request timed out.";
$deadoralive = strpos($dead, $pingresult);
if ($deadoralive == false){
echo "The IP address, $ip, is dead";
} else {
echo "The IP address, $ip, is alive";
}
}
Run Code Online (Sandbox Code Playgroud)
当我使用示例调用此函数时:
pingAddress("127.0.0.1")
Run Code Online (Sandbox Code Playgroud)
回声结果总是"死" - 无论如何.
有人可以在我出错的地方帮助我吗?和/或者有更好的方法来做同样的结果吗?
非常感谢.
更新:已修改代码以包含双引号但仍获得相同(不正确)的结果.
我有一个代理列表,我试图检查哪些是活动的.到目前为止我所做的是通过卷曲连接到每一个,看看他们是否有回应,但我正在寻找更快的东西,类似于http://www.ip-adress.com/Proxy_Checker/.我正在考虑检查端口是否打开或类似的东西.我目前使用的代码如下
<?php
error_reporting(E_ERROR);
//ini_set('memory_limit', '256M');
function hitFormGet($loginURL, $loginFields, $referer, $cookieString, $code)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
// curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
// curl_setopt( $ch, CURLOPT_COOKIE,$cookieString);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate,sdch');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_HEADER, false);
// curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 35);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.11 (KHTML, like …Run Code Online (Sandbox Code Playgroud)