コード例 #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
ファイル: Scanner.cs プロジェクト: atanasmihaylov/lanscan
 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
ファイル: Ping.cs プロジェクト: atanasmihaylov/lanscan
        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
ファイル: Scanner.cs プロジェクト: atanasmihaylov/lanscan
        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
ファイル: Scanner.cs プロジェクト: atanasmihaylov/lanscan
        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
ファイル: UdpPingWrapper.cs プロジェクト: vlhorton/lanscan
        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);
        }
コード例 #16
0
            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
ファイル: UdpPingWrapper.cs プロジェクト: vlhorton/lanscan
        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
ファイル: PingWrapper.cs プロジェクト: atanasmihaylov/lanscan
 public abstract bool PerformPing(IPEndpoint endpoint);
コード例 #19
0
 public abstract bool PerformPing(IPEndpoint endpoint);
コード例 #20
0
ファイル: UdpPingWrapper.cs プロジェクト: vlhorton/lanscan
 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);
 }