powershell - 如果端口打开则抓取横幅

时间:2014-04-01 14:58:14

标签: powershell-v2.0 port-scanning

我已经能够使用PowerShell 2.0使用Web-Request获取http横幅。现在我试图枚举开放端口,如果打开,抓住横幅。我能够获得所有开放的端口 - 这是我必须抓住横幅。它不起作用 - 我收到错误“非连接套接字上不允许操作”。

  $socket = new-object System.Net.Sockets.TCPClient
  $result = $socket.BeginConnect($hostname, $port)
  $success = $result.AsyncWaitHandle.WaitOne($timeout, $true)

   if ($success)
    {
        echo "open"
        $stream = $socket.GetStream()  // have also tried $stream = $result.GetStream()
        $buffer = new-object System.Byte[] 1024
        $encoding = new-object System.Text.AsciiEncoding
        while ($stream.DataAvailable) {
              $read = $stream.Read($buffer, 0, 1024)
               ......  // output data then close stream....

我做错了什么?

0 个答案:

没有答案