DineshShrestha

DineshShrestha

Filter ip in the list

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??

Most Liked

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

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

DineshShrestha

DineshShrestha

sure thank you.

Where Next?

Popular in Questions Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New

We're in Beta

About us Mission Statement