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
Hi.
- use
parts: 2in 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
Thank you for the help. I will try to complete it.
DineshShrestha
sure thank you.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








