-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy path_test_dns_query.cpp
More file actions
183 lines (163 loc) · 5.76 KB
/
_test_dns_query.cpp
File metadata and controls
183 lines (163 loc) · 5.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**
* @file _test_dns_query.cpp
* @brief
*
* @author Yonhgwhan, Roh (somma@somma.kr)
* @date 2018/05/17 15:21 created.
* @copyright (C)Somma, Inc. All rights reserved.
**/
#include "stdafx.h"
#include <crtdbg.h>
#include "_MyLib/src/net_util.h"
#include "_MyLib/src/StopWatch.h"
/// @brief
bool test_ip_to_dns()
{
wchar_t* ips[] = {
L"101.79.137.130", L"101.79.211.75", L"103.105.156.85", L"103.15.158.128",
L"103.15.158.129", L"103.15.158.153", L"103.229.206.27", L"103.231.98.48",
L"103.243.220.231", L"103.243.220.234", L"103.27.148.71", L"103.6.174.105",
L"103.6.174.115", L"103.71.26.125", L"103.84.152.177", L"103.84.152.178",
L"104.124.189.140", L"104.124.243.17", L"104.155.236.164", L"104.16.162.13",
L"104.16.224.240", L"104.16.228.152", L"104.16.249.5", L"104.16.252.5",
L"104.16.253.5", L"104.16.85.20", L"104.16.89.188", L"104.16.89.20",
L"104.17.102.175", L"104.17.103.175", L"104.17.104.175", L"104.17.105.175",
L"104.17.106.175", L"104.17.210.204", L"104.17.235.204", L"104.17.237.204",
L"104.18.24.243", L"104.18.25.243", L"104.19.195.151", L"104.19.196.151",
L"104.19.197.151", L"104.19.198.151", L"104.193.80.60", L"104.198.94.254",
L"104.20.111.39", L"104.20.168.10", L"104.20.169.10", L"104.20.186.5",
L"104.209.47.112", L"104.215.17.202", L"104.215.21.84", L"104.237.191.1",
L"104.24.18.65", L"104.24.246.16", L"104.244.42.200", L"104.244.43.48",
L"104.31.74.124", L"104.31.75.124", L"104.43.203.255", L"104.74.148.124",
L"104.74.148.234", L"104.74.151.71", L"104.74.153.26", L"104.74.154.37",
L"104.74.162.162", L"104.74.165.136", L"104.74.171.196", L"104.74.174.89",
L"104.74.177.25", L"104.74.178.4", L"104.74.182.221", L"104.74.182.242",
L"104.74.188.12", L"104.74.193.168", L"104.74.211.221", L"104.74.220.23",
L"104.74.220.31", L"104.74.247.82", L"104.75.11.224", L"104.75.17.178",
L"104.75.26.190", L"104.75.35.118", L"104.75.42.31", L"104.75.45.149",
L"104.75.8.148", L"104.75.9.216", L"104.76.131.98", L"104.76.140.232",
L"104.76.82.124", L"106.10.193.31", L"106.10.198.33", L"107.6.122.29",
L"108.59.4.173", L"110.10.122.142", L"110.76.141.124", L"111.119.22.152",
L"111.119.22.180", L"111.119.22.184", L"111.221.29.13", L"111.221.29.174",
L"111.221.29.253", L"111.221.29.254", L"111.221.29.30", L"111.221.29.40",
L"111.221.29.46", L"113.29.189.156", L"113.29.189.164", L"113.29.189.47",
L"114.130.4.77", L"117.18.232.133", L"117.18.232.200", L"117.18.232.232",
L"117.18.232.240", L"117.18.237.17", L"117.18.237.245", L"117.18.237.29",
L"117.18.237.42", L"117.18.237.97", L"117.52.130.123", L"118.22.93.111",
L"119.207.64.147", L"119.207.64.153", L"119.207.64.16", L"119.207.64.17",
L"119.207.64.19", L"119.207.64.24", L"119.207.65.176", L"119.207.65.35",
L"119.207.66.145", L"119.207.66.155", L"119.207.66.160", L"119.207.66.185",
L"122.248.234.94", L"125.209.207.10", L"125.209.210.116", L"125.209.218.79",
L"125.209.226.239", L"125.209.230.195", L"125.209.230.238", L"125.209.234.101",
L"125.209.234.81", L"13.107.128.254", L"13.107.136.254", L"13.107.21.200",
L"13.107.246.254", L"13.107.3.128", L"13.107.3.254", L"13.107.42.254",
L"13.107.4.50", L"13.107.54.254", L"13.107.5.88", L"13.107.6.158",
L"13.112.105.162", L"13.112.243.196", L"13.113.112.168", L"13.113.51.110",
L"13.113.51.176", L"13.113.70.177", L"13.114.9.59", L"13.115.0.186",
L"13.115.26.131", L"13.124.96.191", L"13.125.106.166", L"131.253.14.231",
L"131.253.61.100", L"131.253.61.102", L"131.253.61.64", L"131.253.61.66",
L"131.253.61.68", L"131.253.61.70", L"131.253.61.80", L"131.253.61.82",
L"131.253.61.84", L"131.253.61.86", L"131.253.61.96", L"131.253.61.98",
L"13.228.155.108", L"13.228.226.45", L"13.231.12.16", L"13.250.76.141",
L"13.32.67.31", L"134.170.115.62", L"134.170.165.249", L"13.56.96.0",
L"136.147.100.130", L"136.147.100.2", L"136.147.101.2", L"136.147.102.130",
};
uint32_t succ = 0;
uint32_t cache = 0;
uint32_t wire = 0;
StopWatch sw;
sw.Start();
for (int i = 0; i < sizeof(ips) / sizeof(wchar_t*); ++i)
{
uint32_t ip_nb;
_ASSERTE(true == str_to_ipv4(ips[i], ip_nb));
std::list<std::string> dns1;
std::list<std::string> dns2;
if (true == ip_to_dns(ip_nb, false, &dns1))
{
++cache;
++succ;
}
else
{
if (true == ip_to_dns(ip_nb, false, &dns2))
{
++wire;
++succ;
}
}
//log_info "ip=%ws, dns1=%ws, dns2=%ws",
// ips[i],
// dns1.c_str(),
// dns2.c_str()
// log_end;
}
sw.Stop();
log_info "Done. total=%u, succ=%u, cache=%u, wire=%u, elapsed= %f",
sizeof(ips) / sizeof(wchar_t*),
succ,
cache,
wire,
sw.GetDurationMilliSecond() log_end;
return true;
}
bool test_ip_to_dns2()
{
_mem_check_begin
{
//Non - authoritative answer :
//Name: e6030.a.akamaiedge.net
//Address : 23.40.44.189
//Aliases : www.naver.com
// www.naver.com.nheos.com
// www.naver.com.edgekey.net
std::string ip = "23.40.44.189";
std::list<std::string> names;
bool ret = ip_to_dns(str_to_ipv4(ip.c_str()), false, &names);
if (true == ret)
{
std::stringstream strm;
for (const auto& name : names)
{
strm << name << ",";
}
log_info
"ip=%s, name=%s",
ip.c_str(),
strm.str().c_str()
log_end;
}
else
{
log_err
"ip=%s, no name.",
ip.c_str()
log_end;
}
}
_mem_check_end;
return true;
}
bool test_dns_to_ip()
{
_mem_check_begin
{
std::list<std::string> cnames;
std::list<uint32_t> ips;
_ASSERTE(true == dns_to_ip("www.naver.com", false, &cnames, &ips));
log_info "www.naver.com :" log_end;
for (const auto& ip : ips)
{
log_info " - %s", ipv4_to_str(ip).c_str() log_end;
}
for (const auto& cname : cnames)
{
log_info " - %s", cname.c_str() log_end;
}
cnames.clear();
ips.clear();
_ASSERTE(true != dns_to_ip("inv.invalid.xyz", false, &cnames, &ips));
}
_mem_check_end;
return true;
}