Ejemplo n.º 1
0
        public async void TCPIPScan(string ipStart, int portS, int portE, CancellationToken token, bool tt)
        {
            try
            {
                if (await LocalPing(ipStart))
                {
                    string ip4 = ipStart;

                    string ip6  = String.Empty;
                    string host = String.Empty;
                    try
                    {
                        host = Dns.GetHostEntry(ipStart).HostName;
                    }
                    catch (Exception)
                    {
                    }

                    try
                    {
                        foreach (var fd in Dns.GetHostEntry(ipStart).AddressList)
                        {
                            try
                            {
                                if (fd.IsIPv6LinkLocal)
                                {
                                    ip6 = fd.ToString();
                                }
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                    IP iP = new IP()
                    {
                        IPname4 = ip4, IPname6 = ip6, MyHost = host
                    };
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High,
                                              () =>
                    {
                        viewIP.ListIP.Add(iP);
                        IpListView.ItemsSource = viewIP.ListIP.OrderBy(ip => Convert.ToInt32(ip.IPname4.Split('.')[3]));
                        int x = 0;
                        foreach (var f in IpListView.Items)
                        {
                            if (select.IPname4 == ((IP)f).IPname4)
                            {
                                IpListView.SelectedIndex = x;
                            }
                            x++;
                        }
                        //PortListView.ItemsSource = select.Ports;
                    });

                    Task.Run(() => scanPort(portS, portE, iP, iP.IPname4, token));
                }
            }
            catch (Exception ex)
            {
            }
        }