News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

DnsApi - DnsQuery

Started by bozo, August 23, 2005, 10:18:38 AM

Previous topic - Next topic

bozo


comment ~

very basic use of DnsQuery_A

output for "hotmail.com"

   C:\asm_code>mx hotmail.com

   Name:hotmail.com - Type:15 - Exchange:mx2.hotmail.com
   Name:hotmail.com - Type:15 - Exchange:mx3.hotmail.com
   Name:hotmail.com - Type:15 - Exchange:mx4.hotmail.com
   Name:hotmail.com - Type:15 - Exchange:mx1.hotmail.com
   C:\asm_code>

any ideas about this??
i don't know if i'm calling DnsQuery_A properly.

~

.586
.model flat,stdcall

include <\masm32\include\windows.inc>

include <\masm32\include\dnsapi.inc>
includelib <\masm32\lib\dnsapi.lib>

include <\masm32\include\kernel32.inc>
includelib <\masm32\lib\kernel32.lib>

include <\masm32\include\msvcrt.inc>
includelib <\masm32\lib\msvcrt.lib>

include <\masm32\macros\macros.asm>

DNS_QUERY_STANDARD   EQU   00000000h
DNS_QUERY_ACCEPT_TRUNCATED_RESPONSE   EQU   00000001h
DNS_QUERY_USE_TCP_ONLY   EQU   00000002h
DNS_QUERY_NO_RECURSION   EQU   00000004h
DNS_QUERY_BYPASS_CACHE   EQU   00000008h
DNS_QUERY_NO_WIRE_QUERY   EQU   00000010h
DNS_QUERY_NO_LOCAL_NAME   EQU   00000020h
DNS_QUERY_NO_HOSTS_FILE   EQU   00000040h
DNS_QUERY_NO_NETBT   EQU   00000080h
DNS_QUERY_WIRE_ONLY   EQU   00000100h
DNS_QUERY_RETURN_MESSAGE   EQU   00000200h
DNS_QUERY_TREAT_AS_FQDN   EQU   00001000h
DNS_QUERY_DONT_RESET_TTL_VALUES   EQU   00100000h
DNS_QUERY_RESERVED   EQU   0ff000000h
DNS_QUERY_CACHE_ONLY   EQU   <DNS_QUERY_NO_WIRE_QUERY>

DnsQuery_A proto stdcall :DWORD,:DWORD,:DWORD,:DWORD, :DWORD, :DWORD
DnsQuery_UTF8 proto stdcall :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
DnsQuery_W proto stdcall :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD

.data

DNS_ATMA_FORMAT_E164   EQU   1
DNS_ATMA_FORMAT_AESA   EQU   2
DNS_ATMA_MAX_ADDR_LENGTH   EQU   20

DNS_STATUS    typedef SDWORD
PDNS_STATUS typedef ptr SDWORD
IP4_ADDRESS typedef DWORD
PIP4_ADDRESS typedef ptr DWORD
SIZEOF_IP4_ADDRESS   EQU   4

ifdef MIDL_PASS
IP6_ADDRESS   struct
ifdef _WIN64
IP6Qword   QWORD 2 dup (?)
else
IP6Dword   DWORD 4 dup (?)
endif
IP6_ADDRESS   ends

PIP6_ADDRESS typedef ptr IP6_ADDRESS

else
IP6_ADDRESS   union
ifdef _WIN64
IP6Qword   QWORD 2 dup (?)
endif
IP6Dword   DWORD 4 dup (?)
IP6Word   WORD 8 dup (?)
IP6Byte   BYTE 16 dup (?)
ifdef IN6_ADDR
In6   IN6_ADDR   ?
endif
IP6_ADDRESS   ends

PIP6_ADDRESS typedef ptr IP6_ADDRESS
DNS_IP6_ADDRESS typedef IP6_ADDRESS
PDNS_IP6_ADDRESS typedef ptr IP6_ADDRESS

DNS_RECORD_FLAGS   struct
DNS_RECORD_FLAGS_R0   RECORD   Section:2,Delete:1,CharSet:2,Unused:3,nReserved:24
   DNS_RECORD_FLAGS_R0 <>
DNS_RECORD_FLAGS   ends

DNS_TYPE_ZERO   EQU   0000h
DNS_TYPE_A   EQU   0001h
DNS_TYPE_NS   EQU   0002h
DNS_TYPE_MD   EQU   0003h
DNS_TYPE_MF   EQU   0004h
DNS_TYPE_CNAME   EQU   0005h
DNS_TYPE_SOA   EQU   0006h
DNS_TYPE_MB   EQU   0007h
DNS_TYPE_MG   EQU   0008h
DNS_TYPE_MR   EQU   0009h
DNS_TYPE_NULL   EQU   000ah
DNS_TYPE_WKS   EQU   000bh
DNS_TYPE_PTR   EQU   000ch
DNS_TYPE_HINFO   EQU   000dh
DNS_TYPE_MINFO   EQU   000eh
DNS_TYPE_MX   EQU   000fh
DNS_TYPE_TEXT   EQU   0010h
DNS_TYPE_RP   EQU   0011h
DNS_TYPE_AFSDB   EQU   0012h
DNS_TYPE_X25   EQU   0013h
DNS_TYPE_ISDN   EQU   0014h
DNS_TYPE_RT   EQU   0015h
DNS_TYPE_NSAP   EQU   0016h
DNS_TYPE_NSAPPTR   EQU   0017h
DNS_TYPE_SIG   EQU   0018h
DNS_TYPE_KEY   EQU   0019h
DNS_TYPE_PX   EQU   001ah
DNS_TYPE_GPOS   EQU   001bh
DNS_TYPE_AAAA   EQU   001ch
DNS_TYPE_LOC   EQU   001dh
DNS_TYPE_NXT   EQU   001eh
DNS_TYPE_EID   EQU   001fh
DNS_TYPE_NIMLOC   EQU   0020h
DNS_TYPE_SRV   EQU   0021h
DNS_TYPE_ATMA   EQU   0022h
DNS_TYPE_NAPTR   EQU   0023h
DNS_TYPE_KX   EQU   0024h
DNS_TYPE_CERT   EQU   0025h
DNS_TYPE_A6   EQU   0026h
DNS_TYPE_DNAME   EQU   0027h
DNS_TYPE_SINK   EQU   0028h
DNS_TYPE_OPT   EQU   0029h
DNS_TYPE_UINFO   EQU   0064h
DNS_TYPE_UID   EQU   0065h
DNS_TYPE_GID   EQU   0066h
DNS_TYPE_UNSPEC   EQU   0067h
DNS_TYPE_ADDRS   EQU   00f8h
DNS_TYPE_TKEY   EQU   00f9h
DNS_TYPE_TSIG   EQU   00fah
DNS_TYPE_IXFR   EQU   00fbh
DNS_TYPE_AXFR   EQU   00fch
DNS_TYPE_MAILB   EQU   00fdh
DNS_TYPE_MAILA   EQU   00feh
DNS_TYPE_ALL   EQU   00ffh
DNS_TYPE_ANY   EQU   00ffh
DNS_TYPE_WINS   EQU   0ff01h
DNS_TYPE_WINSR   EQU   0ff02h
DNS_TYPE_NBSTAT   EQU   <( DNS_TYPE_WINSR )>

DNS_A_DATA   struct
   IpAddress   IP4_ADDRESS   ?
DNS_A_DATA   ends

PDNS_A_DATA typedef ptr DNS_A_DATA

DNS_PTR_DATA   struct
   pNameHost   LPTSTR   ?
DNS_PTR_DATA   ends

PDNS_PTR_DATA typedef ptr DNS_PTR_DATA

DNS_SOA_DATA   struct
   pNamePrimaryServer   LPTSTR   ?
   pNameAdministrator   LPTSTR   ?
   dwSerialNo   DWORD   ?
   dwRefresh   DWORD   ?
   dwRetry   DWORD   ?
   dwExpire   DWORD   ?
   dwDefaultTtl   DWORD   ?
DNS_SOA_DATA   ends

PDNS_SOA_DATA typedef ptr DNS_SOA_DATA

DNS_MINFO_DATA   struct
   pNameMailbox   LPTSTR   ?
   pNameErrorsMailbox   LPTSTR   ?
DNS_MINFO_DATA   ends

PDNS_MINFO_DATA typedef ptr DNS_MINFO_DATA

DNS_MX_DATA   struct
   pNameExchange   LPTSTR   ?
   wPreference   WORD   ?
   Pad   WORD   ?
DNS_MX_DATA   ends

PDNS_MX_DATA typedef ptr DNS_MX_DATA

DNS_TXT_DATA   struct
   dwStringCount   DWORD   ?
ifdef MIDL_PASS
   pStringArray   LPTSTR 0 dup (?)
else
   pStringArray   LPTSTR 1 dup (?)
   endif
DNS_TXT_DATA   ends

PDNS_TXT_DATA typedef ptr DNS_TXT_DATA

DNS_NULL_DATA   struct
dwByteCount   DWORD   ?
ifdef MIDL_PASS
Data   BYTE 0 dup (?)
else
Data   BYTE 1 dup (?)
endif
DNS_NULL_DATA   ends
endif
PDNS_NULL_DATA typedef ptr DNS_NULL_DATA

DNS_WKS_DATA   struct
   IpAddress   IP4_ADDRESS   ?
   chProtocol   UCHAR   ?
   BitMask   BYTE 1 dup (?)
DNS_WKS_DATA   ends

PDNS_WKS_DATA typedef ptr DNS_WKS_DATA

DNS_AAAA_DATA   struct
   Ip6Address   DNS_IP6_ADDRESS   <>
DNS_AAAA_DATA   ends

PDNS_AAAA_DATA typedef ptr DNS_AAAA_DATA

DNS_SIG_DATA   struct
pNameSigner      LPTSTR   ?
wTypeCovered   WORD   ?
chAlgorithm      BYTE   ?
chLabelCount   BYTE   ?
dwOriginalTtl   DWORD   ?
dwExpiration   DWORD   ?
dwTimeSigned   DWORD   ?
wKeyTag      WORD   ?
Pad         WORD   ?
Signature      BYTE 1 dup (?)
DNS_SIG_DATA   ends

PDNS_SIG_DATA typedef ptr DNS_SIG_DATA

DNS_KEY_DATA   struct
wFlags      WORD   ?
chProtocol      BYTE   ?
chAlgorithm      BYTE   ?
Key         BYTE 1 dup (?)
DNS_KEY_DATA   ends

PDNS_KEY_DATA typedef ptr DNS_KEY_DATA

DNS_LOC_DATA   struct
wVersion   WORD   ?
wSize      WORD   ?
wHorPrec   WORD   ?
wVerPrec   WORD   ?
dwLatitude   DWORD   ?
dwLongitude   DWORD   ?
dwAltitude   DWORD   ?
DNS_LOC_DATA   ends

PDNS_LOC_DATA typedef ptr DNS_LOC_DATA

DNS_NXT_DATA   struct
pNameNext      LPTSTR   ?
wNumTypes      WORD   ?
wTypes      WORD 1 dup (?)
DNS_NXT_DATA   ends

PDNS_NXT_DATA typedef ptr DNS_NXT_DATA

DNS_SRV_DATA   struct
   pNameTarget      LPTSTR   ?
   wPriority      WORD   ?
   wWeight      WORD   ?
   wPort         WORD   ?
   Pad         WORD   ?
DNS_SRV_DATA   ends

PDNS_SRV_DATA typedef ptr DNS_SRV_DATA

DNS_ATMA_DATA   struct
   AddressType      BYTE   ?
   Address      BYTE DNS_ATMA_MAX_ADDR_LENGTH dup (?)
DNS_ATMA_DATA   ends

PDNS_ATMA_DATA typedef ptr DNS_ATMA_DATA

DNS_TKEY_DATA   struct
   pNameAlgorithm      LPTSTR   ?
   pAlgorithmPacket      PBYTE   ?
   pKey            PBYTE   ?
   pOtherData         PBYTE   ?
   dwCreateTime      DWORD   ?
   dwExpireTime      DWORD   ?
   wMode            WORD   ?
   wError         WORD   ?
   wKeyLength         WORD   ?
   wOtherLength      WORD   ?
   cAlgNameLength      UCHAR   ?
   bPacketPointers      BOOL   ?
DNS_TKEY_DATA   ends

PDNS_TKEY_DATA typedef ptr DNS_TKEY_DATA

DNS_TSIG_DATA   struct
   pNameAlgorithm   LPTSTR   ?
   pAlgorithmPacket   PBYTE   ?
   pSignature      PBYTE   ?
   pOtherData      PBYTE   ?
   i64CreateTime   QWORD   ?
   wFudgeTime      WORD   ?
   wOriginalXid   WORD   ?
   wError      WORD   ?
   wSigLength      WORD   ?   
   wOtherLength   WORD   ?
   cAlgNameLength   UCHAR   ?
   bPacketPointers   BOOL   ?
DNS_TSIG_DATA   ends

PDNS_TSIG_DATA typedef ptr DNS_TSIG_DATA

DNS_WINS_DATA   struct
   dwMappingFlag      DWORD   ?
   dwLookupTimeout      DWORD   ?
   dwCacheTimeout      DWORD   ?
   cWinsServerCount      DWORD   ?
   WinsServers      IP4_ADDRESS 1 dup (?)
DNS_WINS_DATA   ends

PDNS_WINS_DATA typedef ptr DNS_WINS_DATA

DNS_WINSR_DATA   struct
   dwMappingFlag   DWORD   ?
   dwLookupTimeout   DWORD   ?
   dwCacheTimeout   DWORD   ?
   pNameResultDomain   LPTSTR   ?
DNS_WINSR_DATA   ends

DNS_RECORD   struct
   pNext    DWORD ?
   pName      LPTSTR   ?
   wType      WORD   ?
   wDataLength   WORD   ?

   union Flags
      pDW   DWORD   ?
      pS   DNS_RECORD_FLAGS   <>
   ends

   dwTtl      DWORD   ?
   dwReserved   DWORD   ?

union Data
   A      DNS_A_DATA      <>
   SOA      DNS_SOA_DATA   <>
   Soa      DNS_SOA_DATA   <>
   aPTR      DNS_PTR_DATA   <>
   bPtr      DNS_PTR_DATA   <>
   NS      DNS_PTR_DATA   <>
   Ns      DNS_PTR_DATA   <>
   CNAME      DNS_PTR_DATA   <>
   Cname      DNS_PTR_DATA   <>
   MB      DNS_PTR_DATA   <>
   Mb      DNS_PTR_DATA   <>
   MD      DNS_PTR_DATA   <>
   Md      DNS_PTR_DATA   <>
   MF      DNS_PTR_DATA   <>
   Mf      DNS_PTR_DATA   <>
   MG      DNS_PTR_DATA   <>
   Mg      DNS_PTR_DATA   <>
   MR      DNS_PTR_DATA   <>
   Mr      DNS_PTR_DATA   <>
   MINFO      DNS_MINFO_DATA   <>
   Minfo      DNS_MINFO_DATA   <>
   RP      DNS_MINFO_DATA   <>
   Rp      DNS_MINFO_DATA   <>
   MX      DNS_MX_DATA      <>
   Mx      DNS_MX_DATA      <>
   AFSDB      DNS_MX_DATA      <>
   Afsdb      DNS_MX_DATA      <>
   RT      DNS_MX_DATA      <>
   Rt      DNS_MX_DATA      <>
   HINFO      DNS_TXT_DATA   <>
   Hinfo      DNS_TXT_DATA   <>
   ISDN      DNS_TXT_DATA   <>
   Isdn      DNS_TXT_DATA   <>
   TXT      DNS_TXT_DATA   <>
   Txt      DNS_TXT_DATA   <>
   X25      DNS_TXT_DATA   <>
   Null      DNS_NULL_DATA   <>
   WKS      DNS_WKS_DATA   <>
   Wks      DNS_WKS_DATA   <>
   AAAA      DNS_AAAA_DATA   <>
   KEY      DNS_KEY_DATA   <>
   Key      DNS_KEY_DATA   <>
   SIG      DNS_SIG_DATA   <>
   Sig      DNS_SIG_DATA   <>
   ATMA      DNS_ATMA_DATA   <>
   Atma      DNS_ATMA_DATA   <>
   NXT      DNS_NXT_DATA   <>
   Nxt      DNS_NXT_DATA   <>
   SRV      DNS_SRV_DATA   <>
   Srv      DNS_SRV_DATA   <>
   TKEY      DNS_TKEY_DATA   <>
   Tkey      DNS_TKEY_DATA   <>
   TSIG      DNS_TSIG_DATA   <>
   Tsig      DNS_TSIG_DATA   <>
   WINS      DNS_WINS_DATA   <>
   Wins      DNS_WINS_DATA   <>
   WINSR      DNS_WINSR_DATA   <>
   WinsR      DNS_WINSR_DATA   <>
   NBSTAT   DNS_WINSR_DATA   <>
   Nbstat   DNS_WINSR_DATA   <>
   ends
DNS_RECORD   ends

main       PROTO :DWORD, :DWORD

stinfo         STARTUPINFO   <?>
bWildCard         DWORD      ?
pEnv            DWORD      ?
pArgv            DWORD      ?
nArgc            DWORD      ?

ppQueryResultsSet      DWORD      ?
pReserved         DWORD      ?

.code
start:
   mov   [bWildCard], FALSE
   invoke crt___getmainargs,addr nArgc,addr pArgv,addr pEnv,[bWildCard],addr stinfo

   invoke main,[nArgc],[pArgv]

   invoke crt_exit

main   PROC argc:DWORD, argv:DWORD

   mov   esi, [argv]

   .IF([argc] == 2)
      invoke DnsQuery_A,
         dword ptr [esi + 4],
         DNS_TYPE_MX,
         DNS_QUERY_STANDARD,
         NULL,
         addr ppQueryResultsSet,
         addr pReserved

      .IF (eax == ERROR_SUCCESS)
         mov   esi, [ppQueryResultsSet]
      
         .REPEAT
            movzx   edx, [esi][DNS_RECORD.wType]
         
            invoke crt_printf,
               chr$(10,'Name:%s - Type:%d - Exchange:%s'),
               dword ptr[esi][DNS_RECORD.pName],
               edx,
               dword ptr[esi][DNS_RECORD.Data.MX.pNameExchange]

               mov   esi, [esi][DNS_RECORD.pNext]
         .UNTIL(esi == 0)
      .ELSE
         invoke crt_printf,chr$(10,'DNS Error!')
      .ENDIF
   .ELSE
      invoke crt_printf,chr$(10,'%s <DOMAIN NAME>'),dword ptr [esi]
   .ENDIF
   ret
main   ENDP

end start


i used teletype tags because it wasn't formatting properly without adjustments under code tags.
just wondering if there is anyone on the boards who has already converted WinDNS.h to WinDNS.INC for assembly programming??

i converted a bit using the help of h2incx by Japheth, the actual code itself seems to work ok.
you basically input a domain name, like "hotmail.com" or "yahoo.com" and it gives smtp server hostname.

Tedd

What is the problem - that you're receiving many entries as a result?
This is fine, you just pick one and use that - if your connection fails, or you get error, etc - you try another one.

As for getting access to the hotmail smtp server - good luck!
Hotmail is web-based, and there is no public access to services like smtp/pop3/imap
No snowflake in an avalanche feels responsible.

bozo

I just thought i was doing something wrong when i noticed alot of mail server names coming back with MX1 prefixed.
But it works fine,


C:\asm_code>mx hotmail.com

Name:hotmail.com - Type:15 - Exchange:mx1.hotmail.com
Name:hotmail.com - Type:15 - Exchange:mx2.hotmail.com
Name:hotmail.com - Type:15 - Exchange:mx3.hotmail.com
Name:hotmail.com - Type:15 - Exchange:mx4.hotmail.com

C:\asm_code>nc -v mx1.hotmail.com 25
DNS fwd/rev mismatch: mx1.hotmail.com != mc1.bay6.hotmail.com
DNS fwd/rev mismatch: mx1.hotmail.com != mail.hotmail.com
DNS fwd/rev mismatch: mx1.hotmail.com != mail.hotmail.com
DNS fwd/rev mismatch: mx1.hotmail.com != mail.hotmail.com
mx1.hotmail.com [64.4.50.99] 25 (smtp) open
220 mc1-f8.hotmail.com Sending unsolicited commercial or bulk e-mail to Microsoft's computer network is prohibited.
Other restrictions are found at http://privacy.msn.com/Anti-spam/.
Violations will result in use of equipment located in California and other states.
Tue, 23 Aug 2005 16:14:56 -0700



there would have to be someway to send email to hotmail users.

PBrennick

It does not run on XP.  It builds, okay, just doesnt like XP, I guess...

Paul
The GeneSys Project is available from:
The Repository or My crappy website

bozo

QuoteIt does not run on XP.  It builds, okay, just doesnt like XP, I guess...

Hmm..this is odd, as i have XP SP2.
What service pack are you running, also, would it have anything to do with UNICODE strings, or your local network connection??