Esempio n. 1
0
        public async Task Run(IOutputInput outputInput)
        {
            this.outputInput = outputInput;
            var address = Common.GetLocalAddress(outputInput);

            if (address == null)
            {
                return;
            }

            var portsString = outputInput.Read("Insert ports (comma separated):", "80, 135, 9989");
            var ports       = new List <int>();

            if (!string.IsNullOrEmpty(portsString))
            {
                foreach (var port in portsString.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList())
                {
                    if (int.TryParse(port, out int p) && !ports.Contains(p))
                    {
                        ports.Add(p);
                    }
                }
            }

            if (ports.Count == 0)
            {
                outputInput.WriteLine("No ports provided");
                return;
            }

            ports.Sort();
            outputInput.WriteLine("Current IP address: " + address.ToString());
            outputInput.WriteLine("Ports to scan: " + string.Join(", ", ports.Select(s => s.ToString())));
            outputInput.WriteLine("TCP Scan started!");
            var scanner = new PortScanner()
            {
                StopOnFirstException = false,
                TasksCount           = 0
            };

            scanner.OnScanProgress += PortScanner_OnScanProgress;
            outputInput.StartTime();
            var result = await scanner.PortScan(new PortScanInput
            {
                Addresses = new List <IPAddress> {
                    address
                },
                Ports   = ports,
                Retries = 1,
                Timeout = 1000
            }, new TCPPortClient());

            outputInput.StopTime();
            var processed = result.GetResults();

            outputInput.WriteLine($"Scan completed. Scanned addresses: {processed.Count}, total scanned ports: {processed.Sum(s => s.Count)}");
        }
Esempio n. 2
0
 protected void StartClient(IOutputInput outputInput, BindingConfigurationBase bindingConfigurationBase)
 {
     using (var client = new Client <ITestService>(bindingConfigurationBase))
     {
         client.Start();
         var message = outputInput.Read("Write message: ", "TestMessage");
         var result  = client.Proxy.Ping(message);
         outputInput.WriteLine("Message from server: " + result);
     }
 }
Esempio n. 3
0
        public static int GetPort(IOutputInput outputInput, int port)
        {
            var portString = outputInput.Read("Insert port:", port.ToString(), s =>
            {
                if (!int.TryParse(s, out int _))
                {
                    return("Invalid port value");
                }
                return(null);
            });

            if (string.IsNullOrEmpty(portString))
            {
                outputInput.WriteLine("Invalid port value");
                return(0);
            }
            return(int.Parse(portString));
        }
Esempio n. 4
0
        public static IPAddress GetMask(IOutputInput outputInput)
        {
            var inputString = outputInput.Read("Insert mask:", "255.255.255.0", s =>
            {
                if (!IPAddress.TryParse(s, out IPAddress _))
                {
                    return("Invalid mask format");
                }
                return(null);
            });

            if (string.IsNullOrEmpty(inputString))
            {
                outputInput.WriteLine("No mask provided");
                return(null);
            }
            return(IPAddress.Parse(inputString));
        }