The attachment didn't come through.� Here it is.
-------------
using System;
using System.Runtime.InteropServices;
namespace NetTools
{
�/// <summary>
�/// Summary description for DNS.
�/// </summary>
�public class DNS
�{
��/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
��/// <summary></summary>
��/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
��//public const UInt16 DNS_TYPE_PTR = 0x000c; // 12
��
��#region / DNS_TYPE definitions \
��public const UInt16 DNS_TYPE_ZERO������� = 0x0000;
��//� RFC 1034/1035
��public const UInt16 DNS_TYPE_A���������� = 0x0001;����� //� 1
��public const UInt16 DNS_TYPE_NS��������� = 0x0002;���� //� 2
��public const UInt16 DNS_TYPE_MD��������� = 0x0003;����� //� 3
��public const UInt16 DNS_TYPE_MF��������� = 0x0004;����� //� 4
��public const UInt16 DNS_TYPE_CNAME������ = 0x0005;���� //� 5
��public const UInt16 DNS_TYPE_SOA�������� = 0x0006;����� //� 6
��public const UInt16 DNS_TYPE_MB��������� = 0x0007;����� //� 7
��public const UInt16 DNS_TYPE_MG��������� = 0x0008;����� //� 8
��public const UInt16 DNS_TYPE_MR��������� = 0x0009;����� //� 9
��public const UInt16 DNS_TYPE_NULL������� = 0x000a;����� //� 10
��public const UInt16 DNS_TYPE_WKS�������� = 0x000b;����� //� 11
��public const UInt16 DNS_TYPE_PTR�������� = 0x000c;����� //� 12
��public const UInt16 DNS_TYPE_HINFO������ = 0x000d;����� //� 13
��public const UInt16 DNS_TYPE_MINFO������ = 0x000e;����� //� 14
��public const UInt16 DNS_TYPE_MX��������� = 0x000f;����� //� 15
��public const UInt16 DNS_TYPE_TEXT������� = 0x0010;����� //� 16
��//� RFC 1183
��public const UInt16 DNS_TYPE_RP��������� = 0x0011;����� //� 17
��public const UInt16 DNS_TYPE_AFSDB������ = 0x0012;����� //� 18
��public const UInt16 DNS_TYPE_X25�������� = 0x0013;����� //� 19
��public const UInt16 DNS_TYPE_ISDN������� = 0x0014;����� //� 20
��public const UInt16 DNS_TYPE_RT��������� = 0x0015;����� //� 21
��//� RFC 1348
��public const UInt16 DNS_TYPE_NSAP������� = 0x0016;����� //� 22
��public const UInt16 DNS_TYPE_NSAPPTR���� = 0x0017;����� //� 23
��//� RFC 2065��� (DNS security)
��public const UInt16 DNS_TYPE_SIG�������� = 0x0018;����� //� 24
��public const UInt16 DNS_TYPE_KEY�������� = 0x0019;����� //� 25
��//� RFC 1664��� (X.400 mail)
��public const UInt16 DNS_TYPE_PX��������� = 0x001a;����� //� 26
��//� RFC 1712��� (Geographic position)
��public const UInt16 DNS_TYPE_GPOS������� = 0x001b;����� //� 27
��//� RFC 1886��� (IPv6 Address)
��public const UInt16 DNS_TYPE_AAAA������� = 0x001c;����� //� 28
��//� RFC 1876��� (Geographic location)
��public const UInt16 DNS_TYPE_LOC�������� = 0x001d;����� //� 29
��//� RFC 2065��� (Secure negative response)
��public const UInt16 DNS_TYPE_NXT�������� = 0x001e;����� //� 30
��//� Patton����� (Endpoint Identifier)
��public const UInt16 DNS_TYPE_EID�������� = 0x001f;����� //� 31
��//� Patton����� (Nimrod Locator)
��public const UInt16 DNS_TYPE_NIMLOC����� = 0x0020;����� //� 32
��//� RFC 2052��� (Service location)
��public const UInt16 DNS_TYPE_SRV�������� = 0x0021;����� //� 33
��//� ATM Standard something-or-another (ATM Address)
��public const UInt16 DNS_TYPE_ATMA������� = 0x0022;����� //� 34
��//� RFC 2168��� (Naming Authority Pointer)
��public const UInt16 DNS_TYPE_NAPTR������ = 0x0023;����� //� 35
��//� RFC 2230��� (Key Exchanger)
��public const UInt16 DNS_TYPE_KX��������� = 0x0024;����� //� 36
��//� RFC 2538��� (CERT)
��public const UInt16 DNS_TYPE_CERT������� = 0x0025;����� //� 37
��//� A6 Draft��� (A6)
��public const UInt16 DNS_TYPE_A6��������� = 0x0026;����� //� 38
��//� DNAME Draft (DNAME)
��public const UInt16 DNS_TYPE_DNAME������ = 0x0027;����� //� 39
��//� Eastlake��� (Kitchen Sink)
��public const UInt16 DNS_TYPE_SINK������� = 0x0028;����� //� 40
��//� RFC 2671��� (EDNS OPT)
��public const UInt16 DNS_TYPE_OPT�������� = 0x0029;���� //� 41
��#endregion
��#region / DNS Query definitions \
��public const UInt32 DNS_QUERY_STANDARD��� = 0x00000000;
��public const UInt32 DNS_QUERY_ACCEPT_TRUNCATED_RESPONSE = 0x00000001;
��public const UInt32 DNS_QUERY_USE_TCP_ONLY = 0x00000002;
��public const UInt32 DNS_QUERY_NO_RECURSION = 0x00000004;
��public const UInt32 DNS_QUERY_BYPASS_CACHE = 0x00000008;
��public const UInt32 DNS_QUERY_NO_WIRE_QUERY = 0x00000010;
��public const UInt32 DNS_QUERY_NO_LOCAL_NAME = 0x00000020;
��public const UInt32 DNS_QUERY_NO_HOSTS_FILE = 0x00000040;
��public const UInt32 DNS_QUERY_NO_NETBT = 0x00000080;
��public const UInt32 DNS_QUERY_WIRE_ONLY = 0x00000100;
��public const UInt32 DNS_QUERY_RETURN_MESSAGE = 0x00000200;
��public const UInt32 DNS_QUERY_TREAT_AS_FQDN = 0x00001000;
��public const UInt32 DNS_QUERY_DONT_RESET_TTL_VALUES = 0x00100000;
��public const UInt32 DNS_QUERY_RESERVED = 0xff000000;
��#endregion
��/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
��/// <summary>Dll Entrypoint for DNS Services.</summary>
��/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
��[DllImport("dnsapi.dll",EntryPoint="DnsQuery_A")]
��public static extern UInt32 DnsQuery(
���string lpstrName,
���UInt16 wType,
���UInt32 fOptions,
���IP4_ARRAY server,
���out IntPtr ppQueryResultsSet,
���UInt32 t3
���);
��/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
��/// <summary>Dll Entrypoint for DNS Services.</summary>
��/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
��[DllImport("dnsapi.dll",EntryPoint="DnsRecordListFree")]
��public static extern void DnsRecordListFree(
���IntPtr ppQueryResultsSet,
���Int32 FreeType
���);
��[DllImport("Ws2_32.dll")]
��public static extern UInt32 inet_addr(string ip);
��/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
��/// <summary></summary>
��/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
��[StructLayout(LayoutKind.Sequential)]
��public class DNS_PTR_DATA
��{
���public string pNameHost = null;
��};
��[StructLayout(LayoutKind.Sequential)]
��public class IP4_ARRAY
��{
���public UInt32������ AddrCount;
���public UInt32[]���� AddrArray; //IP4_ADDRESS
��}
��/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
��/// <summary></summary>
��/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
��[StructLayout(LayoutKind.Sequential)]
��public class DNS_RECORD
��{
���public IntPtr� Next = IntPtr.Zero;
���public string� Name = null;
���public short� Type = 0;
���public short� wDataLength = 0;
���/*
���� union
���� {
����� DWORD�������������� DW;���� // flags as DWORD
����� DNS_RECORD_FLAGS��� S;����� // flags as structure
���� } Flags;
���*/
���public UInt32� Flags = 0;
���public UInt32� dwTtl = 0;
���public UInt32� dwReserved = 0;
���//� Record Data
���/*
���� union
���� {
����� DNS_A_DATA� A;
����� DNS_SOA_DATA SOA, Soa;
����� DNS_PTR_DATA PTR, Ptr, NS, Ns, CNAME, Cname, MB, Mb, MD, Md, MF, Mf, MG,
���Mg, MR, Mr;
����� DNS_MINFO_DATA MINFO, Minfo, RP, Rp;
����� DNS_MX_DATA� MX, Mx, AFSDB, Afsdb, RT, Rt;
����� DNS_TXT_DATA HINFO, Hinfo, ISDN, Isdn, TXT, Txt, X25;
����� DNS_NULL_DATA Null;
����� DNS_WKS_DATA WKS, Wks;
����� DNS_AAAA_DATA AAAA;
����� DNS_KEY_DATA KEY, Key;
����� DNS_SIG_DATA SIG, Sig;
����� DNS_ATMA_DATA ATMA, Atma;
����� DNS_NXT_DATA NXT, Nxt;
����� DNS_SRV_DATA SRV, Srv;
����� DNS_TKEY_DATA TKEY, Tkey;
����� DNS_TSIG_DATA TSIG, Tsig;
����� DNS_WINS_DATA WINS, Wins;
����� DNS_WINSR_DATA WINSR, WinsR, NBSTAT, Nbstat;
���� } Data;
���*/
���public DNS_PTR_DATA Data = null;
��}
��private DNS()
��{��
��}
�}
}
�
----------------------------------------
From: "Greg Ewing" <[EMAIL PROTECTED]>
Sent: Tuesday, April 05, 2005 8:08 AM
To: [email protected]
Subject: re: [AspNetAnyQuestionIsOk] please help me.. DnsQuery()...?
anuj, I've attached a DNS class I wrote/use.� Let me know if you have any
questions.� Here's some code I've used to call it in the past:
private void Page_Load(object sender, System.EventArgs e)
��{
���IntPtr ppQueryResultsSet = IntPtr.Zero;
���try
���{
����UInt32 dns_status = 1;
����//IPAddress.Parse("199.45.32.43").Address
����DNS.IP4_ARRAY server = new NetTools.DNS.IP4_ARRAY();
����server.AddrArray = new UInt32[1];
����server.AddrCount = 1;
����server.AddrArray[0] = DNS.inet_addr("199.45.32.43");
//(UInt32)IPAddress.Parse("199.45.32.43").Address;
����Response.Write(server.AddrArray[0] + "
");
����//723529159
����//IntPtr serv = Marshal.AllocHGlobal(Marshal.SizeOf(server));
����//Marshal.StructureToPtr(server, serv, true);
�
����dns_status = DNS.DnsQuery(
�����"gewing.com",
�����DNS.DNS_TYPE_MX,
�����DNS.DNS_QUERY_BYPASS_CACHE,
�����null,
�����out ppQueryResultsSet,
�����(UInt32)0
�����);
����Response.Write(dns_status + "
");
����if (dns_status == 0)
����{
�����DNS.DNS_RECORD QueryResultsSet = (DNS.DNS_RECORD)Marshal.PtrToStructure(
������ppQueryResultsSet, typeof(DNS.DNS_RECORD));
�����while (!QueryResultsSet.Next.Equals(IntPtr.Zero))
�����{
������Response.Write (QueryResultsSet.Data.pNameHost + "
");
����
������QueryResultsSet = (DNS.DNS_RECORD)Marshal.PtrToStructure(
�������QueryResultsSet.Next, typeof(DNS.DNS_RECORD));
�����}
����}
����else
����{
�����Response.Write ("Error during query");
����}
���}
���catch(Exception exc)
���{
����Response.Write(exc.Message);
���}
���finally
���{
����DNS.DnsRecordListFree(ppQueryResultsSet, 1);�
���}
��}
Greg Ewing [MVP]
www.citidc.com
----------------------------------------
From: Anuj Kumar
Sent: Tuesday, April 05, 2005 7:59 AM
To: [email protected]
Subject: [AspNetAnyQuestionIsOk] please help me.. DnsQuery()...?
Is there any Gentle man in this group who can help me for following
problem,,,,,
I need to develop a utility which can check the status of DNS Server running on
a computer in our local network..
here this utility can be run from any computer in network.. and the mean of
status is whether the DNS Server is running or not... in case of The Primary
DNS Server is down we can use the Alternative DNS Server running on a different
machine...
Please help me.. i am waiting for ur reply....
bye & take care
...anuj
Yahoo! India Matrimony: Find your life partneronline.
[Non-text portions of this message have been removed]
Yahoo! Groups Links
[Non-text portions of this message have been removed]
Yahoo! Groups Links
[Non-text portions of this message have been removed]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/