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; }
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; }
public BrowserPageArgs(IServiceProvider serviceProvider, AppViewModel appViewModel, IPEndpoint endpoint) : base(serviceProvider, appViewModel) { if (endpoint == null) { throw new ArgumentNullException("endpoint"); } m_endpoint = endpoint; }
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; }
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); }
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; } }
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"); } }
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; } }
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); } }
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; }
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; }
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; }
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; }
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); }
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(); }); }
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); }
public abstract bool PerformPing(IPEndpoint endpoint);
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); } }
public void SendTo(byte[] data, IPEndpoint endpoint) { m_socketFactory.m_sendToInvokedHandler(data, endpoint); }