-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
135 lines (117 loc) · 3.36 KB
/
main.cpp
File metadata and controls
135 lines (117 loc) · 3.36 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
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <experimental/iterator>
#include "ip_filter.h"
int main(int, char const **)
{
try
{
std::vector<std::vector<uint32_t> > ip_pool;
ipv4_validate validatorIP;
ipv4_validate validatorTwoTabs(".*\\t.*\\t.*");
for(std::string line; std::getline(std::cin, line); )
{
//my validate: Does the string contain exactly two TABs?
if(validatorTwoTabs(line))
{
std::vector<std::string> v = split(line);
//my validate Ipv4
if(validatorIP(v.at(0)))
{
std::vector<uint32_t> vec_ip = split_ip(v.at(0));
ip_pool.push_back(vec_ip);
}
}
}
// TODO reverse sort
std::sort(ip_pool.begin(), ip_pool.end(), std::greater<std::vector<uint32_t>>());
//print vector
auto printer = [](const auto& cont)
{
/*for(auto it = cont.cbegin(); it != cont.cend(); ++it)
{
if (it != cont.cbegin())
std::cout << ".";
std::cout << *it;
}*/
std::copy(std::begin(cont), std::end(cont), std::experimental::make_ostream_joiner(std::cout, "."));
std::cout << std::endl;
};
for(const auto& ip : ip_pool)
printer(ip);
// 222.173.235.246
// 222.130.177.64
// 222.82.198.61
// ...
// 1.70.44.170
// 1.29.168.152
// 1.1.234.8
// TODO filter by first byte and output
// ip = filter(1)
for(const auto& ip : ip_pool)
if(ip.at(0) == 1)
printer(ip);
// 1.231.69.33
// 1.87.203.225
// 1.70.44.170
// 1.29.168.152
// 1.1.234.8
// TODO filter by first and second bytes and output
// ip = filter(46, 70)
for(const auto& ip : ip_pool)
if(ip.at(0) == 46 && ip.at(1) == 70)
printer(ip);
// 46.70.225.39
// 46.70.147.26
// 46.70.113.73
// 46.70.29.76
// TODO filter by any byte and output
// ip = filter_any(46)
for(const auto& ip : ip_pool)
if(ip.at(0) == 46 || ip.at(1) == 46|| ip.at(2) == 46|| ip.at(3) == 46)
printer(ip);
// 186.204.34.46
// 186.46.222.194
// 185.46.87.231
// 185.46.86.132
// 185.46.86.131
// 185.46.86.131
// 185.46.86.22
// 185.46.85.204
// 185.46.85.78
// 68.46.218.208
// 46.251.197.23
// 46.223.254.56
// 46.223.254.56
// 46.182.19.219
// 46.161.63.66
// 46.161.61.51
// 46.161.60.92
// 46.161.60.35
// 46.161.58.202
// 46.161.56.241
// 46.161.56.203
// 46.161.56.174
// 46.161.56.106
// 46.161.56.106
// 46.101.163.119
// 46.101.127.145
// 46.70.225.39
// 46.70.147.26
// 46.70.113.73
// 46.70.29.76
// 46.55.46.98
// 46.49.43.85
// 39.46.86.85
// 5.189.203.46
}
catch(const std::exception &e)
{
std::cerr << e.what() << std::endl;
}
return 0;
}