예제 #1
0
 private static Uri GetUri(IPEndpoint endpoint)
 {
     var uriScheme = endpoint.Port == 443 ? "https" : "http";
     var uriString = String.Format(CultureInfo.InvariantCulture, "{0}://{1}:{2}", uriScheme, endpoint.Address, endpoint.Port);
     var result = new Uri(uriString);
     return result;
 }
예제 #2
0
 private static ScanNetworkResult ScanEndpoint(CancellationToken userToken, DnsResolverBase resolver, Protocol protocol, IPEndpoint endpoint)
 {
     var status = Ping.PerformPing(endpoint, protocol);
     var hostName = status ? GetHostName(resolver, endpoint) : null;
     var result = new ScanNetworkResult(protocol, endpoint, hostName, status);
     return result;
 }
예제 #3
0
        public BrowserPageArgs(IServiceProvider serviceProvider, AppViewModel appViewModel, IPEndpoint endpoint)
            : base(serviceProvider, appViewModel)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            m_endpoint = endpoint;
        }
예제 #4
0
        public override bool PerformPing(IPEndpoint endpoint)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            var result = m_socket.ConnectAsync(endpoint.Address.HostName, endpoint.ServiceName).AsTask().Wait(ConnectAsyncTimeout);
            return result;
        }
예제 #5
0
        public override bool PerformPing(IPEndpoint endpoint)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            var result = m_socket.ConnectAsync(endpoint.Address.HostName, endpoint.ServiceName).AsTask().Wait(ConnectAsyncTimeout);

            return(result);
        }
예제 #6
0
 private static bool IsRemoteEndpoint(DatagramSocketMessageReceivedEventArgs args, IPEndpoint endpoint)
 {
     try
     {
         var result = args.RemoteAddress.IsEqual(endpoint.Address.HostName) && args.RemotePort.Equals(endpoint.ServiceName);
         return result;
     }
     catch
     {
         return false;
     }
 }
예제 #7
0
        public void NavigateToBrowserPage(IPEndpoint endpoint)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            if (!Frame.Navigate(typeof(BrowserPage), new BrowserPageArgs(m_serviceProvider, this, endpoint)))
            {
                throw new Exception("Failed to create browser page");
            }
        }
예제 #8
0
        public static bool PerformPing(IPEndpoint endpoint, Protocol protocol)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            using (var pingWrapper = CreatePingWrapper(protocol))
            {
                var result = pingWrapper.PerformPing(endpoint);
                return result;
            }
        }
예제 #9
0
        public static bool PerformPing(IPEndpoint endpoint, Protocol protocol)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            using (var pingWrapper = CreatePingWrapper(protocol))
            {
                var result = pingWrapper.PerformPing(endpoint);
                return(result);
            }
        }
예제 #10
0
        public ScanNetworkResult(Protocol protocol, IPEndpoint endpoint, string hostName, bool isAvailable)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }
            if (hostName != null && String.IsNullOrWhiteSpace(hostName))
            {
                throw new ArgumentException("Invalid host name", "hostName");
            }

            m_protocol = protocol;
            m_endpoint = endpoint;
            m_hostName = hostName;
            m_isAvailable = isAvailable;
        }
예제 #11
0
        public override bool PerformPing(IPEndpoint endpoint)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            var task = PingAsync(endpoint);
            if (!task.Wait(PingAsyncTimeout))
            {
                return false;
            }

            var result = task.Result;
            return result;
        }
예제 #12
0
        private static string GetHostName(DnsResolverBase resolver, IPEndpoint endpoint)
        {
            if (resolver == null)
            {
                return null;
            }

            var result = resolver.GetHostName(endpoint.Address);
#if SCREENSHOT
            if (result != null)
            {
                result = result.Replace("example.com", "my-domain-name");
            }
#endif
            return result;
        }
예제 #13
0
        private async Task<bool> PingAsync(IPEndpoint endpoint)
        {
            m_socket.MessageReceived += (sender, e) =>
            {
                var isRemoteEndpoint = IsRemoteEndpoint(e, endpoint);
                m_taskCompletionSource.TrySetResult(isRemoteEndpoint);
            };

            await m_socket.ConnectAsync(endpoint.Address.HostName, endpoint.ServiceName);
            var writer = new DataWriter(m_socket.OutputStream);
            writer.WriteBytes(CanaryData);
            await writer.StoreAsync();

            var result = await m_taskCompletionSource.Task;
            return result;
        }
예제 #14
0
        public static void ScanNetwork(CancellationToken userToken, DnsResolverBase resolver, IPAddressRange addresses, INetworkServiceCore[] networkServices, IProgress<ScanNetworkBatch> progress)
        {
            if (resolver == null)
            {
                throw new ArgumentNullException("resolver");
            }
            if (addresses == null)
            {
                throw new ArgumentNullException("addresses");
            }
            if (networkServices == null)
            {
                throw new ArgumentNullException("networkServices");
            }
            if (progress == null)
            {
                throw new ArgumentNullException("progress");
            }

            var nestedTasks = new List<Task>();
            var chunkSize = GetChunkSize(addresses);
            foreach (var addressChunk in addresses.Chunk(chunkSize))
            {
                userToken.ThrowIfCancellationRequested();

                var nestedTask = Task.Factory.StartNew(() =>
                {
                    foreach (var address in addressChunk)
                    {
                        var results = new List<ScanNetworkResult>();
                        foreach (var networkService in networkServices)
                        {
                            userToken.ThrowIfCancellationRequested();

                            var endpoint = new IPEndpoint(address, networkService.Port);
                            var result = ScanEndpoint(userToken, resolver, networkService.Protocol, endpoint);
                            results.Add(result);
                        }
                        progress.Report(new ScanNetworkBatch(results.ToArray()));
                    }
                });
                nestedTasks.Add(nestedTask);
            }
            Task.WaitAll(nestedTasks.ToArray(), userToken);
        }
예제 #15
0
        public override bool PerformPing(IPEndpoint endpoint)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            var task = PingAsync(endpoint);

            if (!task.Wait(PingAsyncTimeout))
            {
                return(false);
            }

            var result = task.Result;

            return(result);
        }
            public void SendTo(byte[] data, IPEndpoint endpoint)
            {
                Task.Factory.StartNew(async () =>
                {
                    //try
                    //{
                    await m_socket.ConnectAsync(endpoint.Address.HostName, endpoint.Port.ToString(CultureInfo.InvariantCulture));
                    //}
                    //catch (Exception ex)
                    //{
                    //    Logger.Trace("ConnectAsync failed: {0}", ex);
                    //    throw;
                    //}

                    var writer = new DataWriter(m_socket.OutputStream);
                    writer.WriteBytes(data);
                    await writer.StoreAsync();
                });
            }
예제 #17
0
        private async Task <bool> PingAsync(IPEndpoint endpoint)
        {
            m_socket.MessageReceived += (sender, e) =>
            {
                var isRemoteEndpoint = IsRemoteEndpoint(e, endpoint);
                m_taskCompletionSource.TrySetResult(isRemoteEndpoint);
            };

            await m_socket.ConnectAsync(endpoint.Address.HostName, endpoint.ServiceName);

            var writer = new DataWriter(m_socket.OutputStream);

            writer.WriteBytes(CanaryData);
            await writer.StoreAsync();

            var result = await m_taskCompletionSource.Task;

            return(result);
        }
예제 #18
0
 public abstract bool PerformPing(IPEndpoint endpoint);
예제 #19
0
 public abstract bool PerformPing(IPEndpoint endpoint);
예제 #20
0
 private static bool IsRemoteEndpoint(DatagramSocketMessageReceivedEventArgs args, IPEndpoint endpoint)
 {
     try
     {
         var result = args.RemoteAddress.IsEqual(endpoint.Address.HostName) && args.RemotePort.Equals(endpoint.ServiceName);
         return(result);
     }
     catch
     {
         return(false);
     }
 }
예제 #21
0
 public void SendTo(byte[] data, IPEndpoint endpoint)
 {
     m_socketFactory.m_sendToInvokedHandler(data, endpoint);
 }