c#并行扫描端口控制台程序

static void Main(string[] args)

    {<br/>
        Console.WriteLine(&#34;请输入ip&#34;);<br/>
        string ip = Console.ReadLine();<br/>
        Parallel.For(1, 65535, i =&gt; scan(ip, i, 200));<br/>
        Console.WriteLine(&#34;扫描完成&#34;);

} public static void scan(string ip, int port, int timeout)

    {<br/>
        TcpClient tc = new TcpClient();<br/>
        tc.ReceiveTimeout = timeout;<br/>
        try<br/>
        {<br/>
            tc.Connect(ip, port);<br/>
            if (tc.Connected)<br/>
            {<br/>
                Console.WriteLine(&#34;Port {0} is Open&#34;, port.ToString().PadRight(6));<br/>
                Console.WriteLine(&#34;连接成功!!!&#34;);<br/>
            }<br/>
        }<br/>
        catch<br/>
        {<br/>
            //Console.WriteLine(&#34;Port {0} is Closed&#34;, port.ToString().PadRight(6));<br/>
        }<br/>
        finally<br/>
        {<br/>
            tc.Close();<br/>
            tc = null;

}

    }