/// <summary> /// Gets the DNS records of a domain. /// /// </summary> /// <param name="domain">Domain to query for DNS records</param> /// <param name="localDNSIPs">List of local DNS Resolver IPs to do the lookup</param> /// <returns></returns> public async Task <CollatedRecords> GetRecordsOfDomain(Uri domain, List <IPAddress> localDNSIPs) { IList <IPAddress> respIPs = new List <IPAddress>(); IResponse resp = null; foreach (var dnsIP in localDNSIPs) { DnsClient cli = new DnsClient(dnsIP); ClientRequest req = cli.Create(); req.RecursionDesired = true; req.Questions.Add(new Question(Domain.FromString(domain.Host), RecordType.ANY)); try { resp = await req.Resolve(); respIPs = await cli.Lookup(domain.Host); } catch { Console.Error.WriteLine("Swallowed lookup exception."); } if (resp != null && resp.ResponseCode.Equals(ResponseCode.NoError)) { break; } } if (resp == null) { throw new InvalidOperationException("Unable to get a valid response from the domain, check input."); } return(new CollatedRecords(resp, respIPs)); }
protected virtual IResponse ResolveRemote(Request request) { Console.WriteLine("Request From: " + local.Address.ToString()); ClientRequest remoteRequest = client.Create(request); ClientResponse response = remoteRequest.Resolve(); return(response); }
protected virtual IResponse ResolveRemote(Request request) { // WARNING: this function is called from a worker thread if (resolver == null) { return(null); } ClientRequest remoteRequest = resolver.Create(request); return(remoteRequest.Resolve()); }
public static async Task Run([TimerTrigger("0 0 * * * *")] TimerInfo myTimer, ILogger log, CancellationToken cancellationToken) { log.LogInformation($"Checking for Old or Deleted Students: {DateTime.Now}"); var credentials = SdkContext.AzureCredentialsFactory.FromMSI(new MSILoginInformation(MSIResourceType.AppService), AzureEnvironment.AzureGlobalCloud); var azure = Azure.Configure() .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic) .Authenticate(credentials) .WithDefaultSubscription(); var zone = await azure.DnsZones.GetByResourceGroupAsync("rg-contosomasks", "contosomasks.com"); var allNSRecords = await zone.NSRecordSets.ListAsync(true, cancellationToken); if (allNSRecords != null && allNSRecords.Any(ns => !ns.Name.Equals("@"))) { DnsClient client = new DnsClient("8.8.8.8"); foreach (var ns in allNSRecords.Where(ns => !ns.Name.Equals("@"))) { var request = client.Create(); request.Questions.Add(new DNS.Protocol.Question(Domain.FromString($"donotdelete.{ns.Name}.contosomasks.com"), RecordType.TXT)); request.RecursionDesired = true; bool found = false; try { var response = await request.Resolve(); found = response.AnswerRecords != null && response.AnswerRecords.Any(); } catch (Exception) { found = false; } if (!found) { log.LogInformation($"Student {ns.Name} is done, removing subdomain"); await zone.Update().WithoutNSRecordSet(ns.Name).ApplyAsync(); } else { log.LogInformation($"Student {ns.Name} is still active"); } } } }
static async void Run() { try { // Bind to a Domain Name Server DnsClient client = new DnsClient("8.8.8.8"); // Create request bound to 8.8.8.8 ClientRequest request = client.Create(); // Returns a list of IPs IList <IPAddress> ips = await client.Lookup("framesoft.ir"); // Get the domain name belonging to the IP (google.com) //string domain = await client.Reverse("173.194.69.100"); } catch (Exception ex) { } }
protected virtual IResponse ResolveRemote(Request request) { ClientRequest remoteRequest = client.Create(request); return(remoteRequest.Resolve()); }
protected virtual async Task <IResponse> ResolveRemote(Request request) { ClientRequest remoteRequest = client.Create(request); return(await remoteRequest.Resolve()); }
private async Task ResolveName(InConnectionDns cxn) { var name = cxn.Dest.Host; var req = dnsClient.Create(); var domain = new Domain(name); req.Questions.Add(new Question(domain, cxn.RequestType != DnsRequestType.AAAA ? RecordType.A : RecordType.AAAA)); req.OperationCode = OperationCode.Query; req.RecursionDesired = true; IResponse r; try { r = await req.Resolve(); } catch (ResponseException e) { var emptyResp = DnsResponse.Empty(this); emptyResp.Result = ConnectResultEnum.Failed; emptyResp.FailedReason = e.Message; await cxn.SetResult(emptyResp); return; } if (r.ResponseCode != ResponseCode.NoError) { Logger.warning("resolving " + name + ": server returns " + r.ResponseCode); } int count = 0; foreach (var item in r.AnswerRecords) { if (item.Type == RecordType.A || item.Type == RecordType.AAAA) { count++; } } if (count == 0) { if (r.AnswerRecords.Count == 0) { Logger.warning("resolving " + name + ": no answer records"); } else { Logger.warning("resolving " + name + ": answer records without A/AAAA records"); } } var arr = new IPAddress[count]; int?ttl = null; int cur = 0; foreach (var item in r.AnswerRecords) { if (item.Type == RecordType.A || item.Type == RecordType.AAAA) { arr[cur++] = ((IPAddressResourceRecord)item).IPAddress; int newTtl = (int)item.TimeToLive.TotalSeconds; ttl = ttl.HasValue ? Math.Min(newTtl, ttl.Value) : newTtl; } } var resp = new DnsResponse(this, arr) { TTL = ttl }; await cxn.SetResult(resp); }