39 lines
675 B
Ruby
39 lines
675 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
logfile = File.open("teambuilder.pt.log")
|
||
|
data = logfile.read
|
||
|
lines = data.split("\n")
|
||
|
|
||
|
# Gets the IP address from the string
|
||
|
def get_line_ip(line)
|
||
|
pattern = /\b(?:\d{1,3}\.){3}\d{1,3}\b/
|
||
|
line.match(pattern)[0] if line.match(pattern)
|
||
|
end
|
||
|
|
||
|
# Gets the number of times an IP contacted the site
|
||
|
def times_appeared_single(ips, ip_to_check)
|
||
|
counter = 0
|
||
|
ips.each do |ip|
|
||
|
if ip == ip_to_check
|
||
|
counter += 1
|
||
|
end
|
||
|
end
|
||
|
[counter]
|
||
|
end
|
||
|
|
||
|
def get_code_by_ip(ip_address)
|
||
|
|
||
|
end
|
||
|
|
||
|
def get_user_agent(ip)
|
||
|
|
||
|
end
|
||
|
|
||
|
ips = []
|
||
|
lines.each do | line |
|
||
|
previous_ip = ""
|
||
|
ips << get_line_ip(line)
|
||
|
end
|
||
|
|
||
|
puts times_appeared_single(ips, "3.94.209.170")
|