DineshShrestha

DineshShrestha OP

defmodule PurgeOfIps do
# create the module started by application.ex each hour, starts a purge of Ips not seen last 7 days from the list
# get list of ips
def ip_not_listed_7_days do
# get list of ips
seconds_in_seven_days = 604_800
ips = File.read!(“hardcodedList.txt”)
# start the purge of ips not seen last 7 days every hour
ips
|> String.split(~r/\W/, trim: true)
end)
end
end
I have the ips = [
[“192.168.44.152”, “2021-12-16”, “12:44:11.822908”],
[“192.168.44.163”, “2021-12-16”, “12:44:11.822924”],
[“192.168.44.164”, “2021-12-16”, “12:44:11.822931”],
[“192.168.44.165”, “2021-12-16”, “12:44:11.822937”],
[“192.168.44.166”, “2021-12-16”, “12:44:11.822943”],
[“192.168.44.167”, “2021-12-16”, “12:44:11.822962”],
[“192.168.44.168”, “2021-12-16”, “12:44:11.822984”],
[“192.168.44.169”, “2021-12-16”, “12:44:11.822991”],
[“192.168.44.151”, “2021-12-16”, “12:44:11.823005”],
[“192.168.44.153”, “2021-12-16”, “12:44:11.823012”]
]
How to check the list every hour and filter out the ip not seen in last 7 days??

First 10 of 15 Posts Switch mode

dimitarvp

dimitarvp

Can you please format your code with triple backticks – ``` – at the top and the bottom of the code block?

ImNotAVirus

ImNotAVirus

And can you please also provide your hardcodedList.txt file?

DineshShrestha

DineshShrestha OP

it is the same ips in that txt file.

dimitarvp

dimitarvp

Can you show us what have you tried?

DineshShrestha

DineshShrestha OP

I have written in the file with ip and timestamp. which i mentioned in previous comment with code.

eksperimental

eksperimental

Hi.

  1. use parts: 2 in your split function to only split into two items. first will be the IP address, second the date, which you should convert to DateTime or NaiveDateTime.

2 . write a function that will filter your list of entries, you can use the DateTime.compare or DateTime.diff and list the ones that are older than 7 days.
After that run Enum.uniq to return unique ip addresses, and that is your solution to your problem.

Let us know if you have any more questions.

DineshShrestha

DineshShrestha OP

Thank you for the help. I will try to complete it.

DineshShrestha

DineshShrestha OP

But there is a list of list. How do i do it?? For example: [
[“192.168.44.163”, “2021-12-16”, “12:44:11.822924”],
[“192.168.44.164”, “2021-12-16”, “12:44:11.822931”],
[“192.168.44.165”, “2021-12-16”, “12:44:11.822937”],
[“192.168.44.166”, “2021-12-16”, “12:44:11.822943”],
[“192.168.44.167”, “2021-12-16”, “12:44:11.822962”],
[“192.168.44.168”, “2021-12-16”, “12:44:11.822984”],
[“192.168.44.169”, “2021-12-16”, “12:44:11.822991”],
[“192.168.44.151”, “2021-12-16”, “12:44:11.823005”],
[“192.168.44.153”, “2021-12-16”, “12:44:11.823012”]
]
after i implement String.split function. Can you please elaborate it?? I am new to this language.

eksperimental

eksperimental

Let’s work over some real code.
Create a github repot with a Livebook or a sample project.

DineshShrestha

DineshShrestha OP

ok sure

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New

We're in Beta

About us Mission Statement