예제 #1
0
        public void MakeConnection(PortScannerOptions options)
        {
            IPAddress ipAddrObj;

            if (IPAddress.TryParse(options.IpAddressString, out ipAddrObj))
            {
                for (int i = options.PortSearchFloor; i <= options.PortSearchCeiling; i++)
                {
                    IPEndPoint iPEndPoint = new IPEndPoint(ipAddrObj, i);
                    TcpClient  tcpClient  = new TcpClient(iPEndPoint);
                    Thread.Sleep(1000);
                    if (tcpClient.Connected)
                    {
                        Console.WriteLine("Connected");
                    }
                }

                //Parallel.For(options.PortSearchFloor, options.PortSearchCeiling + 1, i =>
                //{
                //    TryConnection(ipAddrObj, i);
                //});
            }
            else
            {
                Console.WriteLine("Failed to connect to socket");
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            PortScannerOptions options = new PortScannerOptions();

            options.IpAddressString   = "172.226.85.43";
            options.PortSearchCeiling = 443;
            options.PortSearchFloor   = 443;

            IpConnection ipconn = new IpConnection();

            ipconn.MakeConnection(options);

            stopWatch.Stop();
            Console.WriteLine("Milliseconds: " + stopWatch.ElapsedMilliseconds);
            Console.Write("Successful ports: ");
            Console.WriteLine(string.Join(", ", ipconn.SuccessfulPorts.ToArray()));
            Console.ReadLine();
        }