private static void Parse_EDUCAUSE(WhoisResult whoisResult, StringReader sr) { string sLine = ""; List <string> nameServers = new List <string>(); StringBuilder errorMessage = new StringBuilder(); bool throwError = true; while (sLine != null) { // read line sLine = sr.ReadLine(); // skip empty lines if (String.IsNullOrEmpty(sLine)) { continue; } // trim whitespaces sLine = sLine.Trim(); // 1. Record not found if (sLine.StartsWith("No Match")) { whoisResult.RecordFound = false; return; // EXIT } // 2. Domain record found if (sLine.StartsWith("Domain Name:")) { // response is ok throwError = false; whoisResult.RecordFound = true; continue; } // 3. Found name servers records if (sLine.StartsWith("Name Servers:")) { // advance to the next line sLine = sr.ReadLine(); while (nameServersRegex.IsMatch(sLine)) { // lookup for ns match Match nsMatch = nameServersRegex.Match(sLine); // add name server record nameServers.Add(nsMatch.Value.ToLower()); // advance to the next line sLine = sr.ReadLine(); } // copy found ns records whoisResult.NameServers = nameServers.ToArray(); return; // EXIT } // 4. Response contains errors errorMessage.AppendLine(sLine); } // throw an error if any if (throwError) { throw new WhoisException(errorMessage.ToString()); } }
private static void Parse_ROMANIAN(WhoisResult whoisResult, StringReader sr) { string sLine = ""; StringBuilder errorMessage = new StringBuilder(); List <string> nameServers = new List <string>(); bool throwError = true; // read while (sLine != null) { // advance to the next line sLine = sr.ReadLine(); // skip empty lines if (String.IsNullOrEmpty(sLine)) { continue; } // trim whitespaces sLine = sLine.Trim(); // 1. Check record status if (sLine.StartsWith("% No entries found for the selected source(s).")) { whoisResult.RecordFound = false; return; // EXIT } // 2. Record found if (sLine.StartsWith("domain-name:")) { // response detected as success throwError = false; whoisResult.RecordFound = true; continue; } // 3. Record found lookup for nameservers if (sLine.StartsWith("nameserver:")) { // loop for name servers records while (nameServersRegex.IsMatch(sLine)) { // lookup for match Match nsMatch = nameServersRegex.Match(sLine); // push nameserver to the list nameServers.Add(nsMatch.Value.ToLower()); // advance to the next line sLine = sr.ReadLine(); } // copy result whoisResult.NameServers = nameServers.ToArray(); return; // EXIT } // 4. Response contains errors errorMessage.AppendLine(sLine); } // throw whois error if (throwError) { throw new WhoisException(errorMessage.ToString()); } }
private static void Parse_NUDOMAINLTD(WhoisResult whoisResult, StringReader whoisResponse) { string sLine = ""; List <string> nameServers = new List <string>(); StringBuilder errorMessage = new StringBuilder(); bool throwError = true; while (sLine != null) { // advance to the next line sLine = whoisResponse.ReadLine(); // skip empty lines if (String.IsNullOrEmpty(sLine)) { continue; } // trim whitespaces sLine = sLine.Trim(); // 1. Record not found if (Regex.IsMatch(sLine, "NO MATCH for domain \\\".*nu\\\" \\(ASCII\\)\\:")) { whoisResult.RecordFound = false; return; // EXIT } // 2. Record found if (Regex.IsMatch(sLine, @"Domain Name \(ASCII\)\: .*nu")) { // response is ok throwError = false; whoisResult.RecordFound = true; continue; } // 3. Copy nameservers if (sLine.Equals("Domain servers in listed order:")) { // advance to the next line sLine = whoisResponse.ReadLine(); // while (nameServersRegex.IsMatch(sLine)) { // lookup for nameserver match Match nsMatch = nameServersRegex.Match(sLine); // add ns record nameServers.Add(nsMatch.Value.ToLower()); // advance to the next line sLine = whoisResponse.ReadLine(); } // copy result whoisResult.NameServers = nameServers.ToArray(); } // 4. Response contains errors errorMessage.AppendLine(sLine); } // throw an error if error message is not empty if (throwError) { throw new WhoisException(errorMessage.ToString()); } }
private static void Parse_AFNIC(WhoisResult whoisResult, StringReader sr) { string sLine = ""; List <string> nameServers = new List <string>(); StringBuilder errorMessage = new StringBuilder(); bool throwError = true; while (sLine != null) { // advance to the next line sLine = sr.ReadLine(); // skip empty lines if (String.IsNullOrEmpty(sLine)) { continue; } // trim whitespaces sLine = sLine.Trim(); // 1. Record not found if (sLine.Equals("%% No entries found in the AFNIC Database.")) { whoisResult.RecordFound = false; return; // EXIT } // 2. Record found if (sLine.StartsWith("domain:")) { // response is ok throwError = false; whoisResult.RecordFound = true; continue; } // 3. Copy nameservers if (sLine.StartsWith("nserver:")) { while (nameServersRegex.IsMatch(sLine)) { // lookup for nameserver match Match nsMatch = nameServersRegex.Match(sLine); // add ns record nameServers.Add(nsMatch.Value.ToLower()); // advance to the next line sLine = sr.ReadLine(); } // copy result whoisResult.NameServers = nameServers.ToArray(); } // 4. Response contains errors errorMessage.AppendLine(sLine); } // throw an error if error message is not empty if (throwError) { throw new WhoisException(errorMessage.ToString()); } }
private static void Parse_UANIC(WhoisResult whoisResult, StringReader whoisResponse) { string sLine = ""; List <string> nameServers = new List <string>(); StringBuilder errorMessage = new StringBuilder(); // According to the research it seems // UA WHOIS servers do not throw any errors, so do we. while (sLine != null) { // advance to the next line sLine = whoisResponse.ReadLine(); // skip empty lines if (String.IsNullOrEmpty(sLine)) { continue; } // trim whitespaces sLine = sLine.Trim(); // 1. Record found if (Regex.IsMatch(sLine, @"domain\: .*ua")) { // response is ok whoisResult.RecordFound = true; continue; } // 2. Copy nameservers if (sLine.StartsWith("nserver")) { // while (sLine.StartsWith("nserver") && nameServersRegex.IsMatch(sLine)) { // lookup for nameserver match Match nsMatch = nameServersRegex.Match(sLine); // add ns record nameServers.Add(nsMatch.Value.ToLower()); // advance to the next line sLine = whoisResponse.ReadLine(); } // copy result whoisResult.NameServers = nameServers.ToArray(); } } }
public static WhoisResult Query(string domain, string tld) { WhoisResult response = new WhoisResult(); try { // check whether tld contains sld parts // applicable for .*.uk names string whoisKey = (tld.IndexOf(".") > -1) ? tld.Substring(tld.LastIndexOf(".") + 1) : tld; // no whois server association for TLD found if (!WhoisSettings.WhoisServers.Contains(whoisKey)) { throw new Exception(GENERIC_FAILURE_MESSAGE); } // get whois server string whoisServer = (string)WhoisSettings.WhoisServers[whoisKey]; // query whois server for specified domain & tld StringReader reader = Whois(whoisServer, domain, tld); // check response is not null if (reader == null) { throw new Exception(EMPTY_RESPONSE_MESSAGE); } // parse whois response response = WhoisParser.Parse(domain + "." + tld, whoisServer, reader); // query succeed response.Success = true; } catch (WhoisException ex) { response.Success = false; response.ResultException = ex; response.ErrorMessage = ex.Message; } catch (Exception ex) { response.Success = false; response.ErrorMessage = ex.Message; response.ResultException = ex; } return(response); }
public static WhoisResult Query(string domain, string tld) { WhoisResult response = new WhoisResult(); try { // check whether tld contains sld parts // applicable for .*.uk names string whoisKey = (tld.IndexOf(".") > -1) ? tld.Substring(tld.LastIndexOf(".") + 1) : tld; // no whois server association for TLD found if (!WhoisSettings.WhoisServers.Contains(whoisKey)) throw new Exception(GENERIC_FAILURE_MESSAGE); // get whois server string whoisServer = (string)WhoisSettings.WhoisServers[whoisKey]; // query whois server for specified domain & tld StringReader reader = Whois(whoisServer, domain, tld); // check response is not null if (reader == null) throw new Exception(EMPTY_RESPONSE_MESSAGE); // parse whois response response = WhoisParser.Parse(domain + "." + tld, whoisServer, reader); // query succeed response.Success = true; } catch (WhoisException ex) { response.Success = false; response.ResultException = ex; response.ErrorMessage = ex.Message; } catch (Exception ex) { response.Success = false; response.ErrorMessage = ex.Message; response.ResultException = ex; } return response; }
private static void Parse_EURID(WhoisResult whoisResult, StringReader sr) { string sLine = ""; StringBuilder errorMessage = new StringBuilder(); List<string> nameServers = new List<string>(); bool throwError = true; // read while (sLine != null) { // advance to the next line sLine = sr.ReadLine(); // skip empty lines if (String.IsNullOrEmpty(sLine)) continue; // trim whitespaces sLine = sLine.Trim(); // 1. Check record status if (sLine.StartsWith("Status:")) { // cleanup status sLine = sLine.Replace("Status:", "").Trim(); // 2. Record found switch (sLine) { case "AVAILABLE": whoisResult.RecordFound = false; return; case "REGISTERED": case "RESERVED": // response detected as success throwError = false; whoisResult.RecordFound = true; break; } } if (sLine.StartsWith("Registrant:")) { // cleanup status sLine = sr.ReadLine(); if (!String.IsNullOrEmpty(sLine)) { whoisResult.RecordFound = true; } } // 3. Record found lookup for nameservers if (sLine.StartsWith("Nameservers:")) { // advance to the next line sLine = sr.ReadLine(); // loop for name servers records while (nameServersRegex.IsMatch(sLine)) { // lookup for match Match nsMatch = nameServersRegex.Match(sLine); // push nameserver to the list nameServers.Add(nsMatch.Value.ToLower()); // advance to the next line sLine = sr.ReadLine(); } // copy result whoisResult.NameServers = nameServers.ToArray(); return; // EXIT } // 4. Response contains errors errorMessage.AppendLine(sLine); } // throw whois error if (throwError) throw new WhoisException(errorMessage.ToString()); }
private static void Parse_INTERNET_NZ(WhoisResult whoisResult, StringReader whoisResponse) { string sLine = ""; List <string> nameServers = new List <string>(); StringBuilder errorMessage = new StringBuilder(); bool throwError = true; while (sLine != null) { // advance to the next line sLine = whoisResponse.ReadLine(); // skip empty lines if (String.IsNullOrEmpty(sLine)) { continue; } // trim whitespaces sLine = sLine.Trim(); // 1. Record found if (Regex.IsMatch(sLine, @"domain_name\: .*nz")) { // response is ok throwError = false; whoisResult.RecordFound = true; continue; } // 2. Match query status if (Regex.IsMatch(sLine, @"query_status\:")) { // Available if (sLine.Contains("220")) { whoisResult.RecordFound = false; return; // EXIT } // Active if (sLine.Contains("200")) { continue; } else { throwError = true; } } // 3. Copy nameservers if (sLine.StartsWith("ns_name_")) { // while (nameServersRegex.IsMatch(sLine)) { // lookup for nameserver match Match nsMatch = nameServersRegex.Match(sLine); // add ns record nameServers.Add(nsMatch.Value.ToLower()); // advance to the next line sLine = whoisResponse.ReadLine(); } // copy result whoisResult.NameServers = nameServers.ToArray(); } // 4. Response contains errors errorMessage.AppendLine(sLine); } // throw an error if error message is not empty if (throwError) { throw new WhoisException(errorMessage.ToString()); } }
public static WhoisResult Parse(string domain, string whoisServer, StringReader whoisResponse) { WhoisResult result = new WhoisResult(); result.Domain = domain; string whoisFormat = (string)WhoisSettings.Parsers[whoisServer]; switch (whoisFormat) { case WhoisSettings.UANIC: Parse_UANIC(result, whoisResponse); break; case WhoisSettings.INTERNIC: Parse_INTERNIC(result, whoisResponse); break; case WhoisSettings.AFFILIAS_LTD: case WhoisSettings.PIR: case WhoisSettings.mTLD: Parse_PIR(result, whoisResponse); break; case WhoisSettings.EDUCAUSE: Parse_EDUCAUSE(result, whoisResponse); break; case WhoisSettings.NOMINET: Parse_NOMINET(result, whoisResponse); break; case WhoisSettings.AUREGISTRY: Parse_AUREGISTRY(result, whoisResponse); break; case WhoisSettings.EURID: Parse_EURID(result, whoisResponse); break; case WhoisSettings.ROMANIAN: Parse_ROMANIAN(result, whoisResponse); break; case WhoisSettings.SWITCH: Parse_SWITCH(result, whoisResponse); break; case WhoisSettings.NEULEVEL: case WhoisSettings.NEUSTAR: Parse_NEUSTAR(result, whoisResponse); break; case WhoisSettings.SIDN: Parse_SIDN(result, whoisResponse); break; case WhoisSettings.AFNIC: Parse_AFNIC(result, whoisResponse); break; case WhoisSettings.TIERED_ACCESS: Parse_TIERED_ACCESS(result, whoisResponse); break; case WhoisSettings.INTERNET_NZ: Parse_INTERNET_NZ(result, whoisResponse); break; default: throw new Exception(String.Format(UNKNOWN_FORMAT_FAILURE, whoisServer)); } return(result); }
private static void Parse_EURID(WhoisResult whoisResult, StringReader sr) { string sLine = ""; StringBuilder errorMessage = new StringBuilder(); List <string> nameServers = new List <string>(); bool throwError = true; // read while (sLine != null) { // advance to the next line sLine = sr.ReadLine(); // skip empty lines if (String.IsNullOrEmpty(sLine)) { continue; } // trim whitespaces sLine = sLine.Trim(); // 1. Check record status if (sLine.StartsWith("Status:")) { // cleanup status sLine = sLine.Replace("Status:", "").Trim(); // 2. Record found switch (sLine) { case "AVAILABLE": whoisResult.RecordFound = false; return; case "REGISTERED": case "RESERVED": // response detected as success throwError = false; whoisResult.RecordFound = true; break; } } if (sLine.StartsWith("Registrant:")) { // cleanup status sLine = sr.ReadLine(); if (!String.IsNullOrEmpty(sLine)) { whoisResult.RecordFound = true; } } // 3. Record found lookup for nameservers if (sLine.StartsWith("Nameservers:")) { // advance to the next line sLine = sr.ReadLine(); // loop for name servers records while (nameServersRegex.IsMatch(sLine)) { // lookup for match Match nsMatch = nameServersRegex.Match(sLine); // push nameserver to the list nameServers.Add(nsMatch.Value.ToLower()); // advance to the next line sLine = sr.ReadLine(); } // copy result whoisResult.NameServers = nameServers.ToArray(); return; // EXIT } // 4. Response contains errors errorMessage.AppendLine(sLine); } // throw whois error if (throwError) { throw new WhoisException(errorMessage.ToString()); } }
public static WhoisResult Parse(string domain, string whoisServer, StringReader whoisResponse) { WhoisResult result = new WhoisResult(); result.Domain = domain; string whoisFormat = (string)WhoisSettings.Parsers[whoisServer]; switch (whoisFormat) { case WhoisSettings.UANIC: Parse_UANIC(result, whoisResponse); break; case WhoisSettings.INTERNIC: Parse_INTERNIC(result, whoisResponse); break; case WhoisSettings.AFFILIAS_LTD: case WhoisSettings.PIR: case WhoisSettings.mTLD: Parse_PIR(result, whoisResponse); break; case WhoisSettings.EDUCAUSE: Parse_EDUCAUSE(result, whoisResponse); break; case WhoisSettings.NOMINET: Parse_NOMINET(result, whoisResponse); break; case WhoisSettings.AUREGISTRY: Parse_AUREGISTRY(result, whoisResponse); break; case WhoisSettings.EURID: Parse_EURID(result, whoisResponse); break; case WhoisSettings.ROMANIAN: Parse_ROMANIAN(result, whoisResponse); break; case WhoisSettings.SWITCH: Parse_SWITCH(result, whoisResponse); break; case WhoisSettings.NEULEVEL: case WhoisSettings.NEUSTAR: Parse_NEUSTAR(result, whoisResponse); break; case WhoisSettings.SIDN: Parse_SIDN(result, whoisResponse); break; case WhoisSettings.AFNIC: Parse_AFNIC(result, whoisResponse); break; case WhoisSettings.TIERED_ACCESS: Parse_TIERED_ACCESS(result, whoisResponse); break; case WhoisSettings.INTERNET_NZ: Parse_INTERNET_NZ(result, whoisResponse); break; default: throw new Exception(String.Format(UNKNOWN_FORMAT_FAILURE, whoisServer)); } return result; }
private static void Parse_PIR(WhoisResult whoisResult, StringReader sr) { string sLine = ""; List <string> nameServers = new List <string>(); StringBuilder errorMessage = new StringBuilder(); bool throwError = true; while (sLine != null) { // advance to the next line sLine = sr.ReadLine(); // skip empty lines if (String.IsNullOrEmpty(sLine)) { continue; } // trim whitespaces sLine = sLine.Trim(); // 1. Record not found if (sLine.StartsWith("NOT FOUND")) { whoisResult.RecordFound = false; return; // EXIT } // 2. Record found if (sLine.StartsWith("Domain Name:")) { // response is ok throwError = false; whoisResult.RecordFound = true; continue; } // 3. Copy nameservers if (sLine.StartsWith("Name Server:")) { while (sLine != null) { // exit when we finish with nameservers if (!sLine.StartsWith("Name Server:")) { break; } // lookup for nameserver match Match nsMatch = nameServersRegex.Match(sLine); if (nsMatch.Success) { nameServers.Add(nsMatch.Value.ToLower()); } // advance to the next line sLine = sr.ReadLine(); } // copy result whoisResult.NameServers = nameServers.ToArray(); return; } // 4. Response contains errors errorMessage.AppendLine(sLine); } // throw an error if error message is not empty if (throwError) { throw new WhoisException(errorMessage.ToString()); } }
private static void Parse_AUREGISTRY(WhoisResult whoisResult, StringReader sr) { string sLine = ""; StringBuilder errorMessage = new StringBuilder(); List<string> nameServers = new List<string>(); bool throwError = true; // read while (sLine != null) { // advance to the next line sLine = sr.ReadLine(); // skip empty lines if (String.IsNullOrEmpty(sLine)) continue; // trim whitespaces sLine = sLine.Trim(); // 1. Record not found if (sLine.StartsWith("No Data Found")) { whoisResult.RecordFound = false; return; // EXIT } // 2. Check record found if (sLine.StartsWith("Domain Name:")) { // response is ok throwError = false; whoisResult.RecordFound = true; continue; } // 3. Record found lookup for nameservers if (sLine.StartsWith("Name Server:")) { // loop for name servers records while (sLine != null) { // lookup for match Match nsMatch = nameServersRegex.Match(sLine); // check lookup status and push nameserver to the list if (nsMatch.Success) nameServers.Add(nsMatch.Value.ToLower()); // advance to the next line sLine = sr.ReadLine(); } // copy result whoisResult.NameServers = nameServers.ToArray(); return; // EXIT } // 4. Response contains errors errorMessage.AppendLine(sLine); } // throw whois error if (throwError) throw new WhoisException(errorMessage.ToString()); }
private static void Parse_NUDOMAINLTD(WhoisResult whoisResult, StringReader whoisResponse) { string sLine = ""; List<string> nameServers = new List<string>(); StringBuilder errorMessage = new StringBuilder(); bool throwError = true; while (sLine != null) { // advance to the next line sLine = whoisResponse.ReadLine(); // skip empty lines if (String.IsNullOrEmpty(sLine)) continue; // trim whitespaces sLine = sLine.Trim(); // 1. Record not found if (Regex.IsMatch(sLine, "NO MATCH for domain \\\".*nu\\\" \\(ASCII\\)\\:")) { whoisResult.RecordFound = false; return; // EXIT } // 2. Record found if (Regex.IsMatch(sLine, @"Domain Name \(ASCII\)\: .*nu")) { // response is ok throwError = false; whoisResult.RecordFound = true; continue; } // 3. Copy nameservers if (sLine.Equals("Domain servers in listed order:")) { // advance to the next line sLine = whoisResponse.ReadLine(); // while (nameServersRegex.IsMatch(sLine)) { // lookup for nameserver match Match nsMatch = nameServersRegex.Match(sLine); // add ns record nameServers.Add(nsMatch.Value.ToLower()); // advance to the next line sLine = whoisResponse.ReadLine(); } // copy result whoisResult.NameServers = nameServers.ToArray(); } // 4. Response contains errors errorMessage.AppendLine(sLine); } // throw an error if error message is not empty if (throwError) throw new WhoisException(errorMessage.ToString()); }
private static void Parse_INTERNET_NZ(WhoisResult whoisResult, StringReader whoisResponse) { string sLine = ""; List<string> nameServers = new List<string>(); StringBuilder errorMessage = new StringBuilder(); bool throwError = true; while (sLine != null) { // advance to the next line sLine = whoisResponse.ReadLine(); // skip empty lines if (String.IsNullOrEmpty(sLine)) continue; // trim whitespaces sLine = sLine.Trim(); // 1. Record found if (Regex.IsMatch(sLine, @"domain_name\: .*nz")) { // response is ok throwError = false; whoisResult.RecordFound = true; continue; } // 2. Match query status if (Regex.IsMatch(sLine, @"query_status\:")) { // Available if (sLine.Contains("220")) { whoisResult.RecordFound = false; return; // EXIT } // Active if (sLine.Contains("200")) continue; else throwError = true; } // 3. Copy nameservers if (sLine.StartsWith("ns_name_")) { // while (nameServersRegex.IsMatch(sLine)) { // lookup for nameserver match Match nsMatch = nameServersRegex.Match(sLine); // add ns record nameServers.Add(nsMatch.Value.ToLower()); // advance to the next line sLine = whoisResponse.ReadLine(); } // copy result whoisResult.NameServers = nameServers.ToArray(); } // 4. Response contains errors errorMessage.AppendLine(sLine); } // throw an error if error message is not empty if (throwError) throw new WhoisException(errorMessage.ToString()); }
private static void Parse_UANIC(WhoisResult whoisResult, StringReader whoisResponse) { string sLine = ""; List<string> nameServers = new List<string>(); StringBuilder errorMessage = new StringBuilder(); // According to the research it seems // UA WHOIS servers do not throw any errors, so do we. while (sLine != null) { // advance to the next line sLine = whoisResponse.ReadLine(); // skip empty lines if (String.IsNullOrEmpty(sLine)) continue; // trim whitespaces sLine = sLine.Trim(); // 1. Record found if (Regex.IsMatch(sLine, @"domain\: .*ua")) { // response is ok whoisResult.RecordFound = true; continue; } // 2. Copy nameservers if (sLine.StartsWith("nserver")) { // while (sLine.StartsWith("nserver") && nameServersRegex.IsMatch(sLine)) { // lookup for nameserver match Match nsMatch = nameServersRegex.Match(sLine); // add ns record nameServers.Add(nsMatch.Value.ToLower()); // advance to the next line sLine = whoisResponse.ReadLine(); } // copy result whoisResult.NameServers = nameServers.ToArray(); } } }
private static void Parse_AUREGISTRY(WhoisResult whoisResult, StringReader sr) { string sLine = ""; StringBuilder errorMessage = new StringBuilder(); List <string> nameServers = new List <string>(); bool throwError = true; // read while (sLine != null) { // advance to the next line sLine = sr.ReadLine(); // skip empty lines if (String.IsNullOrEmpty(sLine)) { continue; } // trim whitespaces sLine = sLine.Trim(); // 1. Record not found if (sLine.StartsWith("No Data Found")) { whoisResult.RecordFound = false; return; // EXIT } // 2. Check record found if (sLine.StartsWith("Domain Name:")) { // response is ok throwError = false; whoisResult.RecordFound = true; continue; } // 3. Record found lookup for nameservers if (sLine.StartsWith("Name Server:")) { // loop for name servers records while (sLine != null) { // lookup for match Match nsMatch = nameServersRegex.Match(sLine); // check lookup status and push nameserver to the list if (nsMatch.Success) { nameServers.Add(nsMatch.Value.ToLower()); } // advance to the next line sLine = sr.ReadLine(); } // copy result whoisResult.NameServers = nameServers.ToArray(); return; // EXIT } // 4. Response contains errors errorMessage.AppendLine(sLine); } // throw whois error if (throwError) { throw new WhoisException(errorMessage.ToString()); } }
private static void Parse_SWITCH(WhoisResult whoisResult, StringReader sr) { string sLine = ""; StringBuilder errorMessage = new StringBuilder(); List<string> nameServers = new List<string>(); bool throwError = true; // read while (sLine != null) { // advance to the next line sLine = sr.ReadLine(); // skip empty lines if (String.IsNullOrEmpty(sLine)) continue; // trim whitespaces sLine = sLine.Trim(); // 1. Check record status if (sLine.StartsWith("We do not have an entry in our database matching your query.")) { whoisResult.RecordFound = false; return; // EXIT } // 2. Record found if (sLine.StartsWith("Domain name:")) { // response detected as success throwError = false; whoisResult.RecordFound = true; continue; } // 3. Record found lookup for nameservers if (sLine.StartsWith("Name servers:")) { // advance to the next line sLine = sr.ReadLine(); // loop for name servers records while (nameServersRegex.IsMatch(sLine)) { // lookup for match Match nsMatch = nameServersRegex.Match(sLine); // push nameserver to the list nameServers.Add(nsMatch.Value.ToLower()); // advance to the next line sLine = sr.ReadLine(); } // copy result whoisResult.NameServers = nameServers.ToArray(); return; // EXIT } // 4. Response contains errors errorMessage.AppendLine(sLine); } // throw whois error if (throwError) throw new WhoisException(errorMessage.ToString()); }
public static CheckDomainResult CheckDomain(int resellerId, string domain, string tld) { // CheckDomainResult result = new CheckDomainResult(); // try { // TopLevelDomain rslTld = GetResellerTopLevelDomain(resellerId, tld); // if (rslTld != null && !rslTld.WhoisEnabled) { // result.Succeed = true; // result.ResultCode = 0; // return(result); } // WhoisResult wResult = WhoisLookup.Query(domain, tld); // query error if (!wResult.Success) { // result.ErrorMessage = wResult.ErrorMessage; // result.Succeed = false; // result.ResultCode = CheckDomainResult.QUERY_ERROR; // return(result); } // whois record found if (wResult.RecordFound) { // result.ResultCode = CheckDomainResult.DOMAIN_BUSY; // result.Succeed = true; // return(result); } // whois record not found - domain is available for purchase result.Succeed = true; // result.ResultCode = 0; } catch (Exception ex) { // result.ErrorMessage = ex.StackTrace; // result.Succeed = false; // result.ResultCode = CheckDomainResult.UNSPECIFIED_ERROR; } // return(result); }
private static void Parse_NEUSTAR(WhoisResult whoisResult, StringReader sr) { string sLine = ""; List<string> nameServers = new List<string>(); StringBuilder errorMessage = new StringBuilder(); bool raiseError = true; while (sLine != null) { // advance to the next line sLine = sr.ReadLine(); // skip empty lines if (String.IsNullOrEmpty(sLine)) continue; // trim whitespaces sLine = sLine.Trim(); // 1. Record not found if (sLine.StartsWith("Not found:")) { whoisResult.RecordFound = false; return; // EXIT } // 2. Record found if (sLine.StartsWith("Domain Name:")) { whoisResult.RecordFound = true; // response detected as success raiseError = false; continue; } // 3. Copy nameservers if (sLine.StartsWith("Name Server:")) { while (nameServersRegex.IsMatch(sLine)) { // lookup for nameserver match Match nsMatch = nameServersRegex.Match(sLine); // add ns record nameServers.Add(nsMatch.Value.ToLower()); // advance to the next line sLine = sr.ReadLine(); } // copy result whoisResult.NameServers = nameServers.ToArray(); return; // EXIT } // 4. Response contains errors errorMessage.AppendLine(sLine); } // throw an error if error message is not empty if (raiseError) throw new WhoisException(errorMessage.ToString()); }