public void SetUp() { _dnsResolver = A.Fake <IDnsResolver>(); _logger = A.Fake <ILogger>(); _organisationalDomainProvider = A.Fake <IOrganisationalDomainProvider>(); _dmarcRecordDnsClient = new DmarcRecordDnsClient(_dnsResolver, _logger, _organisationalDomainProvider); }
/// <summary> /// Applies this configuration to the specified <paramref name="resolver"/>. /// </summary> /// <param name="resolver">The resolver to be configured.</param> /// <exception cref="System.ArgumentNullException"> /// Thrown when <paramref name="resolver"/> is <see langword="null"/>. /// </exception> public override void Apply(IDnsResolver resolver) { DnsStubResolver stub = (DnsStubResolver)resolver; base.Apply(resolver); lock (stub.Servers) { stub.Servers.Clear(); if (this.DiscoverServers) { this.Log.Info("discovering network servers"); foreach (IPEndPoint server in DiscoverNetworkServers()) { stub.Servers.Add(server); this.Log.InfoFormat("discovered server, ep={0}", server); } } foreach (DnsEndPointElement element in this.Servers) { stub.Servers.Add(element.Endpoint); } if (stub.Servers.Count == 0) { this.Log.Error("no servers specified in configuration and dicovery of network servers " + "failed to yield any servers or is disabled"); } } }
/// <summary> /// Create an Http(s) to Socks5 proxy using one or multiple chained proxies /// </summary> /// <param name="proxyList">List of proxies to route through</param> /// <param name="internalServerPort">The port to listen on with the internal server, 0 means it is selected automatically</param> public HttpToSocks5Proxy(ProxyInfo[] proxyList, int internalServerPort = 0) { if (internalServerPort < 0 || internalServerPort > 65535) { throw new ArgumentOutOfRangeException(nameof(internalServerPort)); } if (proxyList == null) { throw new ArgumentNullException(nameof(proxyList)); } if (proxyList.Length == 0) { throw new ArgumentException("proxyList is empty", nameof(proxyList)); } if (proxyList.Any(p => p == null)) { throw new ArgumentNullException(nameof(proxyList), "Proxy in proxyList is null"); } ProxyList = proxyList; InternalServerPort = internalServerPort; dnsResolver = new DefaultDnsResolver(); InternalServerSocket = CreateSocket(); InternalServerSocket.Bind(new IPEndPoint(IPAddress.Loopback, InternalServerPort)); if (InternalServerPort == 0) { InternalServerPort = ((IPEndPoint)(InternalServerSocket.LocalEndPoint)).Port; } ProxyUri = new Uri("http://127.0.0.1:" + InternalServerPort); InternalServerSocket.Listen(8); InternalServerSocket.BeginAccept(OnAcceptCallback, null); }
/// <summary> /// Constructor. /// If no resolver is passed it use <see cref="SystemDnsResolver"/> /// </summary> /// <param name="resolver">A custom DNS Resolver</param> public Socks4(IDnsResolver resolver = null) : base(resolver) { if (resolver == null) { Resolver = new SystemDnsResolver(); } }
/// <summary> /// Create an Http(s) to Socks5 proxy using one or multiple chained proxies /// </summary> /// <param name="proxyList">List of proxies to route through</param> /// <param name="internalServerPort">The port to listen on with the internal server, 0 means it is selected automatically</param> public HttpToSocks5Proxy(ProxyInfo[] proxyList, int internalServerPort = 0) { if (internalServerPort < 0 || internalServerPort > 65535) { throw new ArgumentOutOfRangeException(nameof(internalServerPort)); } if (proxyList == null) { throw new ArgumentNullException(nameof(proxyList)); } if (proxyList.Length == 0) { throw new ArgumentException("proxyList is empty", nameof(proxyList)); } if (proxyList.Any(p => p == null)) { throw new ArgumentNullException(nameof(proxyList), "Proxy in proxyList is null"); } ProxyList = proxyList; InternalServerPort = internalServerPort; dnsResolver = new DefaultDnsResolver(); _socket = CreateSocket(); //_socket.Bind(new IPEndPoint(IPAddress.Any, InternalServerPort));//BYWS:为什么端口是0,还报错 _socket.Bind(new IPEndPoint(IPAddress.Any, 54321)); Console.WriteLine("[HttpToSocks5Proxy---->]socket.Bind: 54321"); if (InternalServerPort == 0) { InternalServerPort = ((IPEndPoint)(_socket.LocalEndPoint)).Port;//BYWS:为什么端口是63037 } //ProxyUri = new Uri("http://127.0.0.1:" + InternalServerPort);//注释掉就成功 _socket.Listen(8); _socket.BeginAccept(OnAcceptCallback, null); }
public DnsMonitorFactory( IEventSubscriber eventSubscriber, IDnsResolver dnsResolver = null) { _eventSubscriber = Ensure.IsNotNull(eventSubscriber, nameof(eventSubscriber)); _dnsResolver = dnsResolver ?? new DnsClientWrapper(); }
/// <summary> /// Applies this configuration to the specified <paramref name="resolver"/>. /// </summary> /// <param name="resolver">The resolver to be configured.</param> /// <exception cref="System.ArgumentNullException"> /// Thrown when <paramref name="resolver"/> is <see langword="null"/>. /// </exception> public virtual void Apply(IDnsResolver resolver) { Guard.NotNull(resolver, "resolver"); resolver.NameSuffix = this.NameSuffix; resolver.Cache = this.CacheInstance; resolver.Transport = this.TransportInstance; }
public DnsService(IDnsWatcherDbContext context, ILogger <DnsService> logger, IDnsServersService dnsServersService, IDnsResolver dnsResolver) { _context = context; _logger = logger; _dnsServersService = dnsServersService; _dnsResolver = dnsResolver; }
public IpEndPointService(IDnsResolver dnsResolver) { // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (dnsResolver == null) { ThrowHelper.ThrowArgumentNullException(nameof(dnsResolver)); } _dnsResolver = dnsResolver; }
/// <summary>Initialize server with specified domain name resolver</summary> /// <param name="resolver"></param> public void Initialize(IDnsResolver resolver) { _resolver = resolver; _udpListener = new UdpListener(); _udpListener.Initialize(53); _udpListener.OnRequest += ProcessUdpRequest; _defaultDns = GetDefaultDNS(); }
public TwisterService(ITwisterHttpClient twisterHttpClient, IImageRenderService imageRenderService, IDnsResolver dnsResolver, IMapper mapper) { _twisterHttpClient = twisterHttpClient; _imageRenderService = imageRenderService; _dnsResolver = dnsResolver; _mapper = mapper; }
public FtpClient(FtpClientConfiguration configuration) { this.Configuration = configuration; if (configuration.Host == null) { throw new ArgumentNullException(nameof(configuration.Host)); } dnsResolver = new DnsResolver(); }
public MediaSourceChecker( IFileDownloader fileDownloader, IPlaylistFileBuilder playlistFileBuilder, IDnsResolver dnsResolver, ICacheManager cache) { this.fileDownloader = fileDownloader; this.playlistFileBuilder = playlistFileBuilder; this.dnsResolver = dnsResolver; this.cache = cache; }
public DynamicHostProvider(List <HostAndPort> serverAddresses, IDnsResolver dnsResolver = null, ILogProducer log = null) { if (serverAddresses.Count == 0) { throw new ArgumentException("A HostProvider may not be empty!"); } m_Log = log ?? new TypeLogger <DynamicHostProvider>(); m_DnsResolver = dnsResolver ?? new DnsResolver(m_Log); m_UnresolvedEndPoints = serverAddresses; }
internal SniEndPointResolver(IDnsResolver dns, SniOptions sniOptions, IRandom rand) { _dns = dns ?? throw new ArgumentNullException(nameof(dns)); _sniOptions = sniOptions ?? throw new ArgumentNullException(nameof(sniOptions)); _random = rand ?? throw new ArgumentNullException(nameof(rand)); if (sniOptions.IsIp) { _endPoint = new IPEndPoint(sniOptions.Ip, sniOptions.Port); } }
public ContactPointParser( IDnsResolver dnsResolver, ProtocolOptions protocolOptions, IServerNameResolver serverNameResolver, bool keepContactPointsUnresolved) { _dnsResolver = dnsResolver ?? throw new ArgumentNullException(nameof(dnsResolver)); _protocolOptions = protocolOptions ?? throw new ArgumentNullException(nameof(protocolOptions)); _serverNameResolver = serverNameResolver ?? throw new ArgumentNullException(nameof(serverNameResolver)); _keepContactPointsUnresolved = keepContactPointsUnresolved; }
public ClusterOptions DnsResolver(IDnsResolver dnsResolver) { if (dnsResolver == null) { throw new ArgumentNullException(nameof(dnsResolver)); } AddSingletonService(dnsResolver); return(this); }
// constructors public DnsMonitor(IDnsMonitoringCluster cluster, IDnsResolver dnsResolver, string lookupDomainName, IEventSubscriber eventSubscriber, CancellationToken cancellationToken) { _cluster = Ensure.IsNotNull(cluster, nameof(cluster)); _dnsResolver = Ensure.IsNotNull(dnsResolver, nameof(dnsResolver)); _lookupDomainName = EnsureLookupDomainNameIsValid(lookupDomainName); _cancellationToken = cancellationToken; _service = "_mongodb._tcp." + _lookupDomainName; _state = DnsMonitorState.Created; eventSubscriber?.TryGetEventHandler(out _sdamInformationEventHandler); }
protected DnsRecordClient( IDnsResolver dnsResolver, ILogger log, QType recordType, string recordName) { _dnsResolver = dnsResolver; _log = log; _recordType = recordType; _recordName = recordName; }
internal SniEndPointResolver(IDnsResolver dns, SniOptions sniOptions, IRandom rand) { _dns = dns; _sniOptions = sniOptions; _random = rand; if (sniOptions.IsIp) { _endPoint = new IPEndPoint(sniOptions.Ip, sniOptions.Port); } }
private DnsMonitor CreateSubject( IDnsMonitoringCluster cluster = null, IDnsResolver dnsResolver = null, string lookupDomainName = null, IEventSubscriber eventSubscriber = null, CancellationToken cancellationToken = default) { cluster = cluster ?? Mock.Of <IDnsMonitoringCluster>(); dnsResolver = dnsResolver ?? Mock.Of <IDnsResolver>(); lookupDomainName = lookupDomainName ?? "a.b.c.com"; return(new DnsMonitor(cluster, dnsResolver, lookupDomainName, eventSubscriber, cancellationToken)); }
private IEndPointResolver Create() { _dnsResolver = Mock.Of <IDnsResolver>(); Mock.Get(_dnsResolver).Setup(m => m.GetHostEntryAsync("cp1")) .ReturnsAsync(new IPHostEntry { AddressList = new[] { IPAddress.Parse("127.0.0.2") } }); var protocolOptions = new ProtocolOptions( EndPointResolverTests.Port, new SSLOptions().SetHostNameResolver(addr => addr.ToString())); return(new EndPointResolver(_dnsResolver, protocolOptions)); }
public HostnameContactPoint( IDnsResolver dnsResolver, ProtocolOptions protocolOptions, IServerNameResolver serverNameResolver, bool keepContactPointsUnresolved, string hostname) { _dns = dnsResolver ?? throw new ArgumentNullException(nameof(dnsResolver)); _protocolOptions = protocolOptions ?? throw new ArgumentNullException(nameof(protocolOptions)); _serverNameResolver = serverNameResolver ?? throw new ArgumentNullException(nameof(serverNameResolver)); _keepContactPointsUnresolved = keepContactPointsUnresolved; _hostname = hostname ?? throw new ArgumentNullException(nameof(hostname)); }
internal ConnectionString(string connectionString, IDnsResolver dnsResolver) { _originalConnectionString = Ensure.IsNotNull(connectionString, nameof(connectionString)); _allOptions = new NameValueCollection(StringComparer.OrdinalIgnoreCase); _unknownOptions = new NameValueCollection(StringComparer.OrdinalIgnoreCase); _authMechanismProperties = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); _compressorsOptions = new CompressorsOptions(); _dnsResolver = Ensure.IsNotNull(dnsResolver, nameof(dnsResolver)); Parse(); _isResolved = _scheme != ConnectionStringScheme.MongoDBPlusSrv; }
public FileDownloader( IDnsResolver dnsResolver, ICacheManager cache, ApplicationSettings applicationSettings) { this.dnsResolver = dnsResolver; this.cache = cache; this.applicationSettings = applicationSettings; httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add( "User-Agent", applicationSettings.UserAgent); }
public MediaSourceChecker( IFileDownloader fileDownloader, IPlaylistFileBuilder playlistFileBuilder, IDnsResolver dnsResolver, ICacheManager cache, ILogger logger, ApplicationSettings applicationSettings) { this.fileDownloader = fileDownloader; this.playlistFileBuilder = playlistFileBuilder; this.dnsResolver = dnsResolver; this.cache = cache; this.logger = logger; this.applicationSettings = applicationSettings; }
/// <summary> /// Forces to update all hints using the given resolver /// </summary> /// <param name="resolver">The resolver to use for resolving the new hints</param> public void Update(IDnsResolver resolver) { Zone zone = new Zone(DomainName.Root); var nameServer = resolver.Resolve<NsRecord>(DomainName.Root, RecordType.Ns); zone.AddRange(nameServer); foreach (var nsRecord in nameServer) { zone.AddRange(resolver.Resolve<ARecord>(nsRecord.NameServer, RecordType.A)); zone.AddRange(resolver.Resolve<AaaaRecord>(nsRecord.NameServer, RecordType.Aaaa)); } zone.AddRange(resolver.Resolve<DnsKeyRecord>(DomainName.Root, RecordType.DnsKey).Where(x => x.IsSecureEntryPoint)); LoadZoneInternal(zone); Save(zone); }
/// <summary> /// Queries a dns resolver for IP addresses of a host as an asynchronous operation. /// </summary> /// <param name="resolver"> The resolver instance, that should be used for queries </param> /// <param name="name"> Host name, that should be queried </param> /// <param name="token"> The token to monitor cancellation requests </param> /// <returns> A list of matching host addresses </returns> public static async Task <List <IPAddress> > ResolveHostAsync(this IDnsResolver resolver, DomainName name, CancellationToken token = default(CancellationToken)) { List <IPAddress> result = new List <IPAddress>(); List <AaaaRecord> aaaaRecords = await resolver.ResolveAsync <AaaaRecord>(name, RecordType.Aaaa, token : token); if (aaaaRecords != null) { result.AddRange(aaaaRecords.Select(x => x.Address)); } List <ARecord> aRecords = await resolver.ResolveAsync <ARecord>(name, token : token); if (aRecords != null) { result.AddRange(aRecords.Select(x => x.Address)); } return(result); }
/// <summary> /// Queries a dns resolver for IP addresses of a host. /// </summary> /// <param name="resolver"> The resolver instance, that should be used for queries </param> /// <param name="name"> Host name, that should be queried </param> /// <returns> A list of matching host addresses </returns> public static List <IPAddress> ResolveHost(this IDnsResolver resolver, DomainName name) { List <IPAddress> result = new List <IPAddress>(); List <AaaaRecord> aaaaRecords = resolver.Resolve <AaaaRecord>(name, RecordType.Aaaa); if (aaaaRecords != null) { result.AddRange(aaaaRecords.Select(x => x.Address)); } List <ARecord> aRecords = resolver.Resolve <ARecord>(name); if (aRecords != null) { result.AddRange(aRecords.Select(x => x.Address)); } return(result); }
public async Task ConnectSocket(Socket socket, EndPoint endpoint, NodeConnectionParameters nodeConnectionParameters, CancellationToken cancellationToken) { var isTor = endpoint.IsTor(); if (AllowOnlyTorEndpoints && !isTor) { throw new InvalidOperationException($"The Endpoint connector is configured to allow only Tor endpoints and the '{endpoint}' enpoint is not one"); } var socksSettings = nodeConnectionParameters.TemplateBehaviors.Find <SocksSettingsBehavior>(); var socketEndpoint = endpoint; var useSocks = isTor || socksSettings?.OnlyForOnionHosts is false || endpoint.IsI2P(); if (useSocks) { if (socksSettings?.SocksEndpoint == null) { throw new InvalidOperationException("SocksSettingsBehavior.SocksEndpoint is not set but the connection is expecting using socks proxy"); } socketEndpoint = NormalizeEndpoint(socksSettings.SocksEndpoint); await socket.ConnectAsync(socketEndpoint, cancellationToken).ConfigureAwait(false); await SocksHelper.Handshake(socket, endpoint, socksSettings.GetCredentials(), cancellationToken).ConfigureAwait(false); } else { if (socketEndpoint is DnsEndPoint dnsEndpoint) { IDnsResolver resolver = DnsResolver.Instance; if (socksSettings?.SocksEndpoint != null) { resolver = socksSettings.CreateDnsResolver(); } var address = (await resolver.GetHostAddressesAsync(dnsEndpoint.Host, cancellationToken)).First(); socketEndpoint = new IPEndPoint(address, dnsEndpoint.Port); } socketEndpoint = NormalizeEndpoint(socketEndpoint); await socket.ConnectAsync(socketEndpoint, cancellationToken).ConfigureAwait(false); } }
public EmailVerifier(IDnsResolver resolver) { this.Resolver = resolver; }
public ServerServicesProvider(ITcpClient tcpClient, IDnsResolver dnsResolver, IPinger pinger) { TcpClient = tcpClient; DnsResolver = dnsResolver; Pinger = pinger; }
public DnsQueryHandler(IDnsResolver dnsResolver) { this.dnsResolver = dnsResolver; }