-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
2,419 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require "http" | ||
require "oga" | ||
|
||
module Ayashige | ||
module Sources | ||
class Source | ||
def initialize | ||
@store = Store.new | ||
end | ||
|
||
def store_newly_registered_domains | ||
raise NotImplementedError, "You must implement #{self.class}##{__method__}" | ||
end | ||
|
||
private | ||
|
||
def html2doc(html) | ||
Oga.parse_html html | ||
rescue StandardError => _ | ||
nil | ||
end | ||
|
||
def xml2doc(xml) | ||
Oga.parse_xml xml | ||
rescue StandardError => _ | ||
nil | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# frozen_string_literal: true | ||
|
||
require "zip" | ||
|
||
module Ayashige | ||
module Sources | ||
class WhoisDS < Source | ||
BASE_URL = "https://whoisds.com/newly-registered-domains" | ||
|
||
def store_newly_registered_domains | ||
date = latest_indexed_date | ||
res = HTTP.get(latest_zip_file_link) | ||
lines = unzip(res.body.to_s) | ||
|
||
lines.each do |line| | ||
domain = Domain.new(line) | ||
next unless domain.suspicious? | ||
|
||
@store.store date, domain.to_s, domain.score | ||
puts "WhoisDS: #{domain} is stored." | ||
end | ||
end | ||
|
||
def unzip(data) | ||
fin = StringIO.new(data) | ||
|
||
lines = [] | ||
Zip::InputStream.open(fin) do |zip_file| | ||
while (entry = zip_file.get_next_entry) | ||
content = entry.get_input_stream.read | ||
lines << content.lines.map(&:chomp) | ||
end | ||
end | ||
lines.flatten | ||
end | ||
|
||
def doc | ||
@doc ||= [].tap do |out| | ||
res = HTTP.get(BASE_URL) | ||
out << xml2doc(res.body.to_s) | ||
end.first | ||
end | ||
|
||
def latest_zip_file_link | ||
@latest_zip_file_link ||= [].tap do |out| | ||
break unless doc | ||
|
||
table = doc.at_css("table") | ||
a = table.at_css("tr > td > a") | ||
out << a.get("href") if a | ||
end.first | ||
end | ||
|
||
def latest_indexed_date | ||
@latest_indexed_date ||= [].tap do |out| | ||
break unless doc | ||
|
||
table = doc.at_css("table") | ||
td = table.at_css("tr > td") | ||
out << td.text.split.first if td | ||
end.first | ||
end | ||
end | ||
end | ||
end |
Binary file not shown.
Oops, something went wrong.