SOL9 Sample: DnsIP4RecordQuery
|
1 Screenshot
2 Source code
/*
* DnsIP4RecordQuery.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL9
// 2011/1/1
// 2011/1/14 Updated
// 2011/1/18 Modified to use DnsRecordQueryT class
#include <sol/WSAInitializer.h>
#include <sol/dns/DnsRecordQueryT.h>
#include <sol/Locale.h>
namespace SOL {
class DnsIP4RecordQuery :public Object {
private:
DnsRecordQueryT<DNS_A_DATA> dns;
public:
/**
* Constructor
*/
DnsIP4RecordQuery(const TCHAR* primaryDnsServer=NULL, const TCHAR* secondaryDnsServer=NULL)
:dns(DNS_TYPE_A, primaryDnsServer, secondaryDnsServer)
{
}
public:
~DnsIP4RecordQuery()
{
}
public:
void start(const TCHAR* hostDomain)
{
//Call query method
int count = dns.query(hostDomain);
//Display the query result(all DNS_A_DATA).
_tprintf(_T("All DNS_A_DATA(count=%d)\n"), count);
dns.display();
//Get the first DNS_A_DATA
DNS_A_DATA data;
dns.getFirst(data);
//Display a structure data of DNS_A_DATA
_tprintf(_T("\nFirst DNS_A_DATA\n"));
DnsData dnsData;
dnsData.display(data);
}
};
}
void _tmain(int argc, TCHAR** argv)
{
if (argc <2) {
_tprintf(_T("Usage:%s hostDomain [primaryDnsServer] [secondaryDnsServer]\n"), argv[0]);
_tprintf(_T("Ex: %s google.com\n"), argv[0]);
_tprintf(_T("Ex: %s google.com 208.67.222.222\n"), argv[0]);
_tprintf(_T("Ex: %s google.com 208.67.222.222 208.67.220.220\n"), argv[0]);
//OpenDNS free dns server list / IP address:
//208.67.222.222
//208.67.220.220
return;
}
const TCHAR* hostDomain = NULL;
const TCHAR* primaryDnsServer = NULL;
const TCHAR* secondaryDnsServer= NULL;
if (argc >= 2) {
hostDomain = argv[1];
}
if (argc >= 3) {
primaryDnsServer = argv[2];
}
if (argc == 4) {
secondaryDnsServer = argv[3];
}
WSAInitializer initializer;
Locale locale;
try {
DnsIP4RecordQuery recordQuery(primaryDnsServer, secondaryDnsServer);
recordQuery.start(hostDomain);
} catch (Exception& ex) {
ex.printf();
} catch (...) {
_tprintf(_T("Exception\n"));
}
}
Last modified: 2 May 2016
Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.