Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ on:
push:
branches:
- master
- test
- feature/github_actions

permissions:
contents: write
actions: write
packages: write
id-token: write
pull-requests: write

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -17,6 +25,7 @@ jobs:
- run: cmake . -DPATCH_VERSION=${{ github.run_number }} -DWITH_BOOST_TEST=ON
- run: cmake --build .
- run: cmake --build . --target package
- run: ls -l ./
- name: Create Release
id: create_release
uses: actions/create-release@v1
Expand All @@ -34,6 +43,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./ip_filter-0.0.${{ github.run_number }}-Linux.deb
asset_name: ip_filter-0.0.${{ github.run_number }}-Linux.deb
asset_path: ./ip_filter-0.1.${{ github.run_number }}-Linux.deb
asset_name: ip_filter-0.1.${{ github.run_number }}-Linux.deb
asset_content_type: application/vnd.debian.binary-package
122 changes: 58 additions & 64 deletions ip_filter.cpp
Original file line number Diff line number Diff line change
@@ -1,64 +1,56 @@
#include <algorithm>
#include <array>
#include <iostream>
#include <string>
#include <vector>

using ip_address = std::array<int, 4>;
using ip_pool_type = std::vector<ip_address>;

using my_vec = std::vector<std::vector<std::string>>;

void OutPutIP(const std::vector<std::string>& vec){
for (auto ip_part = vec.cbegin(); ip_part != vec.cend(); ++ip_part)
{
if (ip_part != vec.cbegin()) std::cout << ".";
std::cout << *ip_part;
void OutPutIP(const ip_address& ip) {
for (auto it = ip.cbegin(); it != ip.cend(); ++it) {
if (it != ip.cbegin()) std::cout << ".";
std::cout << *it;
}
std::cout << std::endl;
}

void FilterAny(my_vec& vector, const std::string& any) {
for (auto& row : vector) {
if (std::find(row.begin(), row.end(), any) != row.end()) {
OutPutIP(row);
std::cout << std::endl;
void FilterAny(const ip_pool_type& ip_pool, int any) {
for (const auto& ip : ip_pool) {
if (std::find(ip.begin(), ip.end(), any) != ip.end()) {
OutPutIP(ip);
}
}
}

void FilterOutput(my_vec& vector, std::string fst) {
for (auto& row : vector)
if (row[0] == fst) {
OutPutIP(row);
std::cout << std::endl;
void FilterOutput(const ip_pool_type& ip_pool, int fst) {
for (const auto& ip : ip_pool) {
if (ip[0] == fst) {
OutPutIP(ip);
}
}
}

void FilterOutput(my_vec& vector, std::string fst, std::string snd) {
for (auto& row : vector)
if (row[0] == fst && row[1] == snd) {
OutPutIP(row);
std::cout << std::endl;
void FilterOutput(const ip_pool_type& ip_pool, int fst, int snd) {
for (const auto& ip : ip_pool) {
if (ip[0] == fst && ip[1] == snd) {
OutPutIP(ip);
}
}
}


struct MySort {
bool operator()(const std::vector<std::string>& vec1, const std::vector<std::string>& vec2) const {
for (size_t i = 0; i < 4; ++i) {
int num1 = std::stoi(vec1[i]);
int num2 = std::stoi(vec2[i]);

if (num1 != num2)
return num1 < num2;
}
return false;
bool operator()(const ip_address& ip1, const ip_address& ip2) const {
return ip1 > ip2;
}
};

auto Split(const std::string &str, char d) -> std::vector<std::string> {
auto SplitStr(const std::string& str, char d) -> std::vector<std::string> {
std::vector<std::string> r;
std::string::size_type start = 0;
std::string::size_type stop = str.find_first_of(d);

while(stop != std::string::npos)
while (stop != std::string::npos)
{
r.push_back(str.substr(start, stop - start));

Expand All @@ -71,45 +63,47 @@ auto Split(const std::string &str, char d) -> std::vector<std::string> {
return r;
}

int main()
{
try
{
my_vec ip_pool;
ip_address Split(const std::string& str, char d) {
ip_address result{};
std::string::size_type start = 0;
std::string::size_type stop = str.find_first_of(d);

for (int i = 0; i < 4; ++i) {
result[i] = std::stoi(str.substr(start, stop - start));
start = stop + 1;
stop = str.find_first_of(d, start);
}

return result;
}

int main() {
try {
ip_pool_type ip_pool;

for(std::string line; std::getline(std::cin, line);)
{
std::vector<std::string> v = Split(line, '\t');
for (std::string line; std::getline(std::cin, line);) {
std::vector<std::string> v = SplitStr(line, '\t');
ip_pool.push_back(Split(v.at(0), '.'));
}

// TODO reverse lexicographically sort DONE
std::sort(ip_pool.begin(), ip_pool.end(), MySort());
for(const auto & ip : ip_pool)
{
for(auto ip_part = ip.cbegin(); ip_part != ip.cend(); ++ip_part)
{
if (ip_part != ip.cbegin())
{
std::cout << ".";

}
std::cout << *ip_part;
}
std::cout << std::endl;

for (const auto& ip : ip_pool) {
OutPutIP(ip);
}

//std::cout << "Filter by 1st byte"<< std::endl;
FilterOutput(ip_pool, "1");
//std::cout << "Filter by 1st and 2nd byte"<< std::endl;
FilterOutput(ip_pool, "46", "70");
//std::cout << "Filter any"<< std::endl;
FilterAny(ip_pool, "46");
std::cout << "Filter by 1st byte (1):" << std::endl;
FilterOutput(ip_pool, 1);

std::cout << "Filter by 1st and 2nd byte (46, 70):" << std::endl;
FilterOutput(ip_pool, 46, 70);

std::cout << "Filter any (46):" << std::endl;
FilterAny(ip_pool, 46);
}
catch(const std::exception &e)
{
catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
}

return 0;
}
}