【问题标题】:Automatically redirect browser to many ip addresses using PHP or Javascript使用 PHP 或 Javascript 自动将浏览器重定向到多个 IP 地址
【发布时间】:2011-04-30 07:44:00
【问题描述】:

我需要访问大量 IP 地址以查看它们是否处于活动状态。所以我的计划是一遍又一遍地重定向浏览器,然后只需使用后退按钮查看每个页面。最好的方法是什么?

我很可能会有一组 IP 地址。喜欢:

array(234.324, 2343.323432, 234.234, 234.4543)

然后我可以使用某种脚本语言来循环浏览并将浏览器重定向到这些。期待看到一些很酷的解决方案。

【问题讨论】:

    标签: php javascript ip-address


    【解决方案1】:

    使用cURL

    【讨论】:

      【解决方案2】:

      对我来说,这些看起来不像 IP 地址,但无论如何。为什么不让您的代码获取您有兴趣检查的每个页面?

      【讨论】:

      • 我很确定他输入了随机数作为示例,而不是实际数据。
      【解决方案3】:

      不建议这样做。

      如果你有一个支持 PHP 的服务器,你可以 ping 每个域:

      <?php
      function pingDomain($domain){
          $starttime = microtime(true);
          $file      = fsockopen ($domain, 80, $errno, $errstr, 10);
          $stoptime  = microtime(true);
          $status    = 0;
      
          if (!$file) $status = -1;  // Site is down
          else {
              fclose($file);
              $status = ($stoptime - $starttime) * 1000;
              $status = floor($status);
          }
          return $status;
      }
      ?>
      

      【讨论】:

      • 这很好,但如果页面处于活动状态,我必须从页面获取信息。所以我必须实际查看页面。
      • 在这种情况下,只需下载每个页面:test.com",0); echo $data; ?>
      • 是的,我就是这么想的,就像 Noctine 可能在下面做的那样。创建一个文件,说明此 ip 在线或离线,如果在线包含链接。
      【解决方案4】:

      在 Kovshenin 的回复中,这是我最近制作的一个工具,可以帮助您。

      <html>
      <head>
      <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
      
      <script type="text/javascript">
      $(document).ready(function(){
      
          $('#error_toggle').click(function() {
      
              $('#error_details').slideToggle('slow', function() {
      
              });
      
          });
      
          $('#success_toggle').click(function() {
      
              $('#success_details').slideToggle('slow', function() {
      
              });
      
          });
      
      });
      
      </script>
      
      <style>
      div
      {
      font-family: arial;
      font-size: 12px;
      }
      
      #message
      {
      font-weight: bold;
      font-size: 16px;
      }
      
      #error_toggle
      {
      width: 250px;
      font-weight: bold;
      text-align: center;
      line-height: 25px;
      background: #23ae66;
      color: #ffffff;
      height: 25px;
      cursor: pointer;
      }
      
      #error_details 
      {
      display: none;
      background: #2b2b2b;
      padding: 5px;
      color: #ffffff;
      width: 240px;
      }
      
      #success_toggle
      {
      width: 350px;
      font-weight: bold;
      text-align: center;
      line-height: 25px;
      background: #23ae66;
      color: #ffffff;
      height: 25px;
      cursor: pointer;
      }
      
      #success_details 
      {
      width: 340px;
      display: none;
      padding: 5px;
      color: #ffffff;
      background: #2b2b2b;
      }
      </style>
      </head>
      <body>
      <?php
      
      //Setting up the correct URL and stripping it of un-needed content
      $url = $_GET['url'];
      
          $unwanted_args = array('http://', 'www.');
      
          $clean_url = str_replace($unwanted_args, '', $url);
          $clean_url = trim($clean_url);
      
      //Initalizing CURL
      $set_curl = curl_init($url);
      
          // Setting the array for which headers to return.
          $headers = array('Expect:');
      
          //Setting required CURL options
          curl_setopt($set_curl, CURLOPT_FAILONERROR, true);
          curl_setopt($set_curl, CURLINFO_HEADER_OUT, true);
          curl_setopt($set_curl, CURLOPT_HTTPHEADER, $headers);
          curl_setopt($set_curl, CURLOPT_TIMEOUT, 1);
          curl_setopt($set_curl, CURLOPT_HEADER, false);
          curl_setopt($set_curl, CURLOPT_RETURNTRANSFER, true);
          curl_setopt($set_curl, CURLOPT_USERAGENT,  "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
      
              //Execute request
              curl_exec($set_curl);
      
          //Check to see if the website is down
          if(curl_error($set_curl)) {
      
              echo '<div id="message">' . $clean_url . ' is down</div>';
      
              echo '<div id="error_toggle">Details</div>';
              echo '<div id="error_details">';
      
              echo  curl_error($set_curl) . '<br />';
              echo 'Error number: ' . curl_errno($set_curl) . '<br />';
      
              echo '</div>';
      
          }
          //Else display success message
          else {
      
              $info = curl_getinfo($set_curl);
      
              echo '<div id="message">Success! <a href="' . $info['url'] . '">' . $clean_url . '</a> is currently online</div>';
      
              echo '<div id="success_toggle">Details</div>';
              echo '<div id="success_details">';
      
              echo 'Url: ' . $info['url'] . '<br />';
              echo 'Total Time: ' . $info['total_time'] . ' Seconds<br />';
              echo 'Average download speed: ' . $info['speed_download'] . ' bytes<br />';
              echo 'Content Type: ' . $info['content_type'] . '<br />';
              echo 'Queried with: ' . $info['request_header'] . '<br />';
      
              echo '</div>';
      
      
          }
      //Close CURL conncetion.
      curl_close($set_curl);
      
      ?>
      </body>
      </html>
      

      【讨论】:

      • 这个工具太棒了,只需要添加一个循环,也许还有一些其他的模组,应该都设置好了。非常感谢。
      • 谢谢,意义重大!需要注意的是,对于 HTTPS,您可能会遇到一些错误,如果返回代码高于 400(主要是 404 和 500)并且超时设置为 1 秒,它将返回网站为关闭。只是需要考虑一些事项。
      猜你喜欢
      • 1970-01-01
      • 2010-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-20
      • 1970-01-01
      • 2016-06-25
      • 2019-06-19
      相关资源
      最近更新 更多