Здравствуйте! Необходимо получить mx запись на winsock, google и yandex не помогли )) там для с++ ток dnsquery.
для дельфы юзай модуль WinDNS - в инете рапросто найти можно. вот код функции Code: function MXResolve(Domain: PChar): string; var pQueryResultsSet: PDNS_RECORDA; Name: PChar; begin pQueryResultsSet := nil; if DnsQuery_A(Domain, DNS_TYPE_MX, DNS_QUERY_STANDARD, nil, @pQueryResultsSet, nil) = 0 then begin Result:=pQueryResultsSet^.Data.MX.pNameExchange; GlobalFree(dword(pQueryResultsSet)); end; end; функции даешь адрес сервера, типа yandex.ru, а она возвращает тебе MX запись. А потом обычный резолвинг чтобы узнать IP
А если хочешь на винсок, то бири в руки Rfc Dns и в соответствии со спецификаций формируй запрос. Создавай сокет Udp и черезе него оправляй данный напрямую Dns серверу
_http://www.delphifr.com/codes/DNS_29334.aspx _http://softsearch.ru/programs/16-747-ip-works-mx-download.shtml
http://www.delphifr.com/codes/DNS_29334.aspx А зачем тут регаться? Протопал дальше по ссылке и все вот твое счастье: http://files.codes-sources.com/fichier.aspx?id=29334&f=dnsApi%5clibrary%5cWinDNS.pas
Функция не работает пишу так: procedure TForm1.Button1Click(Sender: TObject); begin form1.memo1.lines.add(MXResolve('mail.ru')); end; Вылетает прога....
Может юзаешь кривой WinDNS У меня пашет всё норм Вот я юзаю этот: Code: //****************************************************************************** // Nom : WinDns.pas // Utilisation : Fonction et Type pour l'acces a DnsApi.dll // Auteur : [email protected] // Date : 27 Aout 2003 // // Modifications : // Date : //****************************************************************************** unit WinDNS; interface uses Windows; const // Options for DnsQuery DNS_QUERY_STANDARD = 0; DNS_QUERY_ACCEPT_TRUNCATED_RESPONSE = 1; DNS_QUERY_USE_TCP_ONLY = 2; DNS_QUERY_NO_RECURSION = 4; DNS_QUERY_BYPASS_CACHE = 8; //autres DNS_ATMA_MAX_ADDR_LENGTH = 20; DNS_ATMA_AESA_ADDR_LENGTH = 20; DNS_TYPE_A = 1; DNS_TYPE_CNAME = 5; DNS_TYPE_PTR = 12; DNS_TYPE_MX = 15; DNS_UPDATE_SECURITY_USE_DEFAULT = 0; type IP6_ADDRESS = array[0..3] of dword; IP4_ADDRESS = DWORD; DNS_A_DATA = IP4_ADDRESS; DNS_PTR_DATA = PChar; DNS_PTR_DATAA = DNS_PTR_DATA; DNS_PTR_DATAW = DNS_PTR_DATA; DNS_AAAA_DATA = IP6_ADDRESS; DNS_STATUS = LongInt; PIP4_ARRAY = ^IP4_ARRAY; //validation d'un nom DNS DNS_NAME_FORMAT = (DnsNameDomain, DnsNameDomainLabel, DnsNameHostnameFull, DnsNameHostnameLabel, DnsNameWildcard, DnsNameSrvRecord); //definie le type de liberation pour avec DnsFreeRecordList DNS_FREE_TYPE = ( DnsFreeFlat, DnsFreeRecordList, DnsFreeParsedMessageFields ); //tableau d'adresse IP IP4_ARRAY = record AddrCount: DWORD; AddrArray: array[0..10] of IP4_ADDRESS; //[0..10] end; DNS_SRV_DATAA = record pNameTarget: PChar; wPriority: Word; wWeighty: Word; wPorty: Word; Pady: Word; // keep ptrs DWORD aligned end; DNS_TSIG_DATAA = record pNameAlgorithm: PChar; pAlgorithmPacket: ^Byte; pSignature: ^Byte; pOtherData: ^Byte; i64CreateTime: longlong; wFudgeTime: Word; wOriginalXid: Word; wError: Word; wSigLength: Word; wOtherLength: Word; cAlgNameLength: UCHAR; bPacketPointers: Boolean; end; DNS_NXT_DATAA = record pNameNext: PChar; wNumTypes: Word; wTypes: array[0..1] of Word; end; DNS_WINSR_DATA = record dwMappingFlag: DWORD; dwLookupTimeout: DWORD; dwCacheTimeout: DWORD; pNameResultDomain: PWideChar; end; DNS_WINSR_DATAA = record dwMappingFlag: DWORD; dwLookupTimeout: DWORD; dwCacheTimeout: DWORD; pNameResultDomain: PChar; end; DNS_RECORD_FLAGS = record Section: DWORD; //DWORD Section : 2; Delete: DWORD; //DWORD Delete : 1; CharSet: DWORD; //DWORD CharSet : 2; Unused: DWORD; //DWORD Unused : 3; Reserved: DWORD; //DWORD Reserved : 24; end; DNS_TXT_DATAA = record dwStringCount: DWORD; pStringArray: array[0..10] of PChar; end; DNS_NULL_DATA = record dwByteCount: DWORD; Data: array[0..10] of Byte; end; DNS_KEY_DATA = record wFlags: Word; chProtocol: Byte; chAlgorithm: Byte; Key: array[0..0] of Byte; end; DNS_SIG_DATAA = record pNameSigner: PChar; wTypeCovered: Word; chAlgorithm: Byte; chLabelCount: Byte; dwOriginalTtl: DWORD; dwExpiration: DWORD; dwTimeSigned: DWORD; wKeyTag: Word; Pad: Word; // keep Byte field aligned Signature: array[0..0] of Byte; end; DNS_ATMA_DATA = record AddressType: Byte; Address: array[0..(DNS_ATMA_MAX_ADDR_LENGTH - 1)] of Byte; end; DNS_WKS_DATA = record IpAddress: IP4_ADDRESS; chProtocol: UCHAR; BitMask: array[0..0] of Byte; // BitMask[1]; end; DNS_MX_DATAA = record pNameExchange: PChar; wPreference: Word; Pad: Word; end; DNS_MINFO_DATAA = record pNameMailbox: PChar; pNameErrorsMailbox: PChar; end; DNS_WINS_DATA = record dwMappingFlag: DWORD; dwLookupTimeout: DWORD; dwCacheTimeout: DWORD; cWinsServerCount: DWORD; WinsServers: array[0..0] of IP4_ADDRESS; end; DNS_TKEY_DATAA = record pNameAlgorithm: PChar; pAlgorithmPacket: ^Byte; pKey: ^Byte; pOtherData: ^Byte; dwCreateTime: DWORD; dwExpireTime: DWORD; wMode: Word; wError: Word; wKeyLength: Word; wOtherLength: Word; cAlgNameLength: UCHAR; bPacketPointers: Boolean; end; DNS_SOA_DATAA = record pNamePrimaryServer: PChar; pNameAdministrator: PChar; dwSerialNo: DWORD; dwRefresh: DWORD; dwRetry: DWORD; dwExpire: DWORD; dwDefaultTtl: DWORD; end; //probleme non resolu lorsqu'on utilise les flags de type S TFlags = record case Integer of 1: (DW: DWORD); // flags as DWORD 2: (S: ^DNS_RECORD_FLAGS); // flags as structure ??? end; TDataA = record case Integer of 1: (A: DNS_A_DATA); // A; 2: (SOA: DNS_SOA_DATAA); // SOA, Soa; 3: (PTR: DNS_PTR_DATAA); //PTR, Ptr, NS, Ns, CNAME, Cname, MB, Mb, MD, Md, MF, Mf, MG, Mg, MR, Mr; 4: (MINFO: DNS_MINFO_DATAA); //MINFO, Minfo, RP, Rp; 5: (MX: DNS_MX_DATAA); //MX, Mx, AFSDB, Afsdb, RT, Rt; 6: (HINFO: DNS_TXT_DATAA); //HINFO, Hinfo, ISDN, Isdn, TXT, Txt, X25; 7: (Null: DNS_NULL_DATA); //Null; 8: (WKS: DNS_WKS_DATA); //WKS, Wks; 9: (AAAA: DNS_AAAA_DATA); //AAAA; 10: (KEY: DNS_KEY_DATA); //KEY, Key; 11: (SIG: DNS_SIG_DATAA); //SIG, Sig; 12: (ATMA: DNS_ATMA_DATA); //ATMA, Atma; 13: (NXT: DNS_NXT_DATAA); //NXT, Nxt; 14: (SRV: DNS_SRV_DATAA); //SRV, Srv; 15: (TKEY: DNS_TKEY_DATAA); //TKEY, Tkey; 16: (TSIG: DNS_TSIG_DATAA); //TSIG, Tsig; 17: (DWINS: DNS_WINS_DATA); //WINS, Wins; 18: (WINSR: DNS_WINSR_DATA); //WINSR, WinsR, NBSTAT, Nbstat; end; PDNS_RECORDA = ^DNS_RECORDA; DNS_RECORDA = record pnext: PDNS_RECORDA; // struct _DnsRecordW * pName: PChar; //PSTR wType: Word; //WORD //WORD wType; wDataLength: Word; //WORD flags: TFlags; // dwTtl: DWORD; //DWORD; dwReserved: DWORD; //DWORD; Data: TDataA; end; //------------------------------------------------------------------------------ //Fonctions //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ //voir un enregistrement function DnsQuery_A( pszName: PChar; wType: Word; Options: DWORD; aipServers: PIP4_ARRAY; ppQueryResults: Pointer; pReserved: Pointer ): DNS_STATUS; stdcall; external 'dnsapi.dll'; //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ //ajouter, modifier et supprimer un enregistrement function DnsModifyRecordsInSet_A( pAddRecords: PDNS_RECORDA; pDeleteRecords: PDNS_RECORDA; Options: DWORD; hContext: Hwnd; pServerList: PIP4_ARRAY; pReserved: Pointer ): DNS_STATUS; stdcall; external 'dnsapi.dll'; //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ //verifie si un nom DNS est correct function DnsValidateName_A( pszName: PChar; Format: DNS_NAME_FORMAT ): DNS_STATUS; stdcall; external 'dnsapi.dll'; //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ //supprime la memoire aloue pour la reponse par un DNS_QUERY procedure DnsRecordListFree( pRecordList: PDNS_RECORDA; FreeType: DNS_FREE_TYPE ); stdcall; external 'dnsapi.dll'; //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ //supprime la memoire aloue pour la reponse par un DNS_QUERY //procedure DnsFreeRecordListDeep( // pRecordList: PDNS_RECORDA; // FreeType: DNS_FREE_TYPE // ); stdcall; external 'dnsapi.dll'; //------------------------------------------------------------------------------ implementation end.