konakona
Dream Afar.
konakona
PHP实现端口扫描

code:  <?php

set_time_limit(0);
error_reporting(0);

echo "PHP Portscanner by KONAKONA.\n\n";

if($argc == 3)
{
  if(strpos($argv[2], "-"))
  {
    $ports = explode("-", $argv[2]);
  }
  else
  {
    $port = $argv[2];
  }
  $host = $argv[1];
}
else
{
  echo "Syntax: php $argv[0] 127.0.0.1 1-65535\n";
  exit;
}

while(true)
{
  if(isset($ports))
  {
    if($ports[0] < 1)
    {
      $start = 1;
    }
    else
    {
      $start = $ports[0];
    }
    if($ports[1] > 65535)
    {
      $end = 65535;
    }
    else
    {
      $end = $ports[1];
    }

    for($start; $start <= $end; $start++)
    {
      $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
      if(socket_connect($sock, $host, $start))
      {
        echo "Port $start is open.\n";
        socket_close($sock);
      }
      else
      {
        echo "Port $start is not open.\n";
        socket_close($sock);
      }
    }
    break;
  }
  else
  {
    $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    if(socket_connect($sock, $host, $port))
    {
      echo "Port $port is open.\n";
      socket_close($sock);
    }
    else
    {
      echo "Port $port is not open.\n";
      socket_close($sock);
    }
    break;
  }
}

?>
赞赏
https://secure.gravatar.com/avatar/3b712b34a0e1b689cfb524c9c6bcdc47?s=256&r=g

团哥

文章作者

继续玩我的CODE,让别人说去。 低调,就是这么自信。

发表评论

textsms
account_circle
email

konakona

PHP实现端口扫描
code: <?php set_time_limit(0); error_reporting(0); echo "PHP Portscanner by KONAKONA.\n\n"; if($argc == 3) { if(strpos($argv[2], "-")) { $ports = ex…
扫描二维码继续阅读
2009-10-26