private void WriteHeader(DnsHeader header) { bool printedWarning = false; WriteLine("HEADER:"); WriteLine(); WriteLine("Opcode: {0}, Rcode: {1}, Id: {2}, Flags: {3}", DnsUtility.ToString(header.OpCode), header.ResponseCode.ToString().ToUpperInvariant(), header.Id, GetHeaderFlags(header)); WriteLine("Question: {0}, Answer: {1}, Authority: {2}, Additional: {3}", header.QuestionCount, header.AnswerCount, header.AuthorityCount, header.AdditionalCount); WriteLine(); if (header.IsTruncated) { WriteLine("WARNING: answer was truncated"); printedWarning = true; } if (header.IsRecursionDesired && !header.IsRecursionAllowed && !header.IsAuthorative) { WriteLine("WARNING: recursion was requested but disallowed"); printedWarning = true; } if (printedWarning) { WriteLine(); } }
/// <summary> /// Writes a formatted usage message to the output. /// </summary> /// <param name="format">The format specification.</param> /// <param name="args">The format arguments.</param> protected override void WriteUsage(string format, params object[] args) { if (!string.IsNullOrEmpty(format)) { WriteLine(format, args); WriteLine(); } WriteLine("[@server] [qtype] [qclass] qname"); WriteLine(" - retrieve info about qname"); WriteLine(" server: query server name or forward server index"); WriteLine(" qtype: query type (A,CNAME,MX,NS,PTR,SOA,TXT,...)"); WriteLine(" qclass: query class (IN,CH,HS,ANY)"); WriteLine(" qname: query target name"); WriteLine("set opt [value]"); WriteLine(" - set specified option, where opt is one of:"); WriteLine(" qtype: default qtype (current:{0})", DnsUtility.ToString(this.DefaultQueryType)); WriteLine(" qclass: default qclass (current:{0})", DnsUtility.ToString(this.DefaultQueryClass)); WriteLine(" suffix: appends name to each query (current:{0})", this.NameSuffix); WriteLine(" reverse: reverse ips before display (state:{0})", GetOptionOnOff(NDigOptions.ReverseAddrs)); WriteLine(" sort: sort section before display (state:{0})", GetOptionOnOff(NDigOptions.SortRecords)); WriteLine(" header: header display mode (state:{0})", GetOptionOnOff(NDigOptions.WriteHeader)); WriteLine(" answer: answer section display mode (state:{0})", GetOptionOnOff(NDigOptions.WriteAnswer)); WriteLine(" question: question section display mode (state:{0})", GetOptionOnOff(NDigOptions.WriteQuestion)); WriteLine(" authority: authority section display mode (state:{0})", GetOptionOnOff(NDigOptions.WriteAuthority)); WriteLine(" additional: additional section display mode (state:{0})", GetOptionOnOff(NDigOptions.WriteAdditional)); WriteLine(" stats: query stats display mode (state:{0})", GetOptionOnOff(NDigOptions.WriteStats)); WriteLine(" noempty: suppress empty section display (state:{0})", GetOptionOnOff(NDigOptions.SuppressEmptySections)); WriteLine(" nologo: suppress program logo (state:{0})", GetOptionOnOff(NDigOptions.SuppressLogo)); WriteLine("config"); WriteLine(" - print resolver configuration"); WriteLine("servers"); WriteLine(" - print forward server list"); WriteLine("version"); WriteLine(" - print version and copyright header"); WriteLine("help, ?"); WriteLine(" - print help"); WriteLine("exit [save]"); WriteLine(" - exit program"); WriteLine(" save: save configuration (default:yes)"); }
/// <summary> /// Returns a <see cref="System.String"/> representation of this instance. /// </summary> /// <returns>A <see cref="System.String"/> representation of this instance.</returns> public override string ToString() { return(DnsUtility.Format("{0} {1}", base.ToString(), DnsUtility.ToString(this.Data))); }
/// <summary> /// Returns a <see cref="System.String"/> representation of this instance. /// </summary> /// <returns>A <see cref="System.String"/> representation of this instance.</returns> public override string ToString() { return(DnsUtility.Format("{0} {1} {2} {3} {4} {5} {6} {7}", base.ToString(), this.Master, this.RMbox, this.Serial, DnsUtility.ToString(this.Refresh), DnsUtility.ToString(this.Retry), DnsUtility.ToString(this.Expire), DnsUtility.ToString(this.Minimum))); }
private void DoSetCommand(string[] args) { switch (args[0].ToLowerInvariant()) { case "suffix": DnsName suffix = null; if (args.Length == 2 && !DnsName.TryParse(args[1], out suffix)) { WriteUsage("value: '{0}' is not a valid name", args[1]); return; } this.NameSuffix = suffix; WriteLine("suffix set: {0}", this.NameSuffix); break; case "qclass": DnsQueryClass qclass = DnsQueryClass.IN; if (args.Length == 2 && !TryParseEnum(args[1], out qclass)) { WriteUsage("value: '{0}' is not a valid qclass", args[1]); return; } this.DefaultQueryClass = qclass; WriteLine("qclass set: {0}", DnsUtility.ToString(this.DefaultQueryClass)); break; case "qtype": DnsQueryType qtype = DnsQueryType.A; if (args.Length == 2 && !TryParseEnum(args[1], out qtype)) { WriteUsage("value: '{0}' is not a valid qtype", args[1]); return; } this.DefaultQueryType = qtype; WriteLine("qtype set: {0}", DnsUtility.ToString(this.DefaultQueryType)); break; case "reverse": ParseBooleanOption(NDigOptions.ReverseAddrs, "reverse", args); break; case "sort": ParseBooleanOption(NDigOptions.SortRecords, "sort", args); break; case "header": ParseBooleanOption(NDigOptions.WriteHeader, "header", args); break; case "question": ParseBooleanOption(NDigOptions.WriteQuestion, "question", args); break; case "answer": ParseBooleanOption(NDigOptions.WriteAnswer, "answer", args); break; case "authority": ParseBooleanOption(NDigOptions.WriteAuthority, "authority", args); break; case "additional": ParseBooleanOption(NDigOptions.WriteAdditional, "additional", args); break; case "stats": ParseBooleanOption(NDigOptions.WriteStats, "stats", args); break; case "noempty": ParseBooleanOption(NDigOptions.SuppressEmptySections, "noempty", args); break; case "nologo": ParseBooleanOption(NDigOptions.SuppressLogo, "nologo", args); break; default: WriteUsage("opt: '{0}' is not a valid option", args[0]); return; } }