コード例 #1
0
        /// <summary>
        /// 查询此类型的记录列表,如果查询失败会返回原因
        /// </summary>
        public Result <List <string> > QueryAll(string domain, DNSQueryOptions options = DNSQueryOptions.STANDARD)
        {
            var           rtv  = new Result <List <string> >();
            List <string> list = new List <string>();

            rtv.Value = list;

            if (String.IsNullOrEmpty(domain))
            {
                rtv.error("查询" + RecordType.Name + "记录域名不能为空");
                return(rtv);
            }
            try {
                var tdRes = TransformDomain(domain);
                if (tdRes.IsError)
                {
                    tdRes.errorTo(rtv);
                    return(rtv);
                }
                domain = tdRes.Value;

                IntPtr ptr1 = IntPtr.Zero;
                IntPtr ptr2 = IntPtr.Zero;
                Record rec;

                var type = Types[RecordType.Name];
                int num  = DnsQuery(ref domain, type, options, 0, ref ptr1, 0);
                if (num != 0)
                {
                    rtv.error("查询出错[" + num + "]");
                    return(rtv);
                }
                for (ptr2 = ptr1; !ptr2.Equals(IntPtr.Zero); ptr2 = rec.pNext)
                {
                    rec = (Record)Marshal.PtrToStructure(ptr2, RecordType);
                    if (rec.wType == type)
                    {
                        list.Add(GetVal(rec));
                    }
                }
                DnsRecordListFree(ptr2, 0);

                return(rtv);
            } catch (Exception e) {
                rtv.fail("查询" + RecordType.Name + "记录出错:" + e.Message, e.ToString());
                return(rtv);
            }
        }
コード例 #2
0
        /// <summary>
        /// 查询一条记录,如果没有记录或查询失败会返回原因
        /// </summary>
        public Result <string> QueryOne(string domain, DNSQueryOptions options = DNSQueryOptions.STANDARD)
        {
            var rtv = new Result <string>();
            var res = QueryAll(domain, options);

            if (res.IsError)
            {
                res.errorTo(rtv);
                return(rtv);
            }
            var val = res.Value;

            if (val.Count == 0)
            {
                rtv.error("未查询到" + RecordType.Name + "记录");
                return(rtv);
            }

            rtv.Value = val[0];
            return(rtv);
        }
コード例 #3
0
 private static extern int DnsQuery([MarshalAs(UnmanagedType.VBByRefStr)] ref string pszName, int wType, DNSQueryOptions options, int aipServers, ref IntPtr ppQueryResults, int pReserved);