| skipped 11 lines |
12 | 12 | | """ |
13 | 13 | | import requests |
14 | 14 | | import bisect |
| 15 | + | import hashlib |
| 16 | + | import os |
15 | 17 | | from opensquat import __VERSION__ |
16 | 18 | | |
17 | 19 | | from colorama import Fore, Style |
| skipped 2 lines |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | class Domain: |
23 | | - | |
24 | 25 | | """ |
25 | 26 | | The Domain class with handle all the functions related to |
26 | 27 | | the domain verifications. |
| skipped 96 lines |
123 | 124 | | ): |
124 | 125 | | self.list_file_keywords.append(line) |
125 | 126 | | |
| 127 | + | def check_latest_feeds(self): |
| 128 | + | |
| 129 | + | URL = self.URL + self.URL_file + ".md5" |
| 130 | + | |
| 131 | + | print("[*] Checking for the latest feeds...") |
| 132 | + | |
| 133 | + | # User-Agent |
| 134 | + | ver = "openSquat-" + __VERSION__ |
| 135 | + | headers = {'User-Agent': ver} |
| 136 | + | |
| 137 | + | try: |
| 138 | + | response = requests.get(URL, headers=headers) |
| 139 | + | except requests.exceptions.RequestException: |
| 140 | + | return False |
| 141 | + | |
| 142 | + | if (response.status_code != 200): |
| 143 | + | return False |
| 144 | + | |
| 145 | + | latest_checksum = response.content.decode('utf-8') |
| 146 | + | latest_checksum = latest_checksum.replace("\n", "") |
| 147 | + | latest_checksum = latest_checksum.strip() |
| 148 | + | |
| 149 | + | response.close() |
| 150 | + | |
| 151 | + | # Compare if local file is the latest |
| 152 | + | if os.path.exists(self.domain_filename): |
| 153 | + | with open(self.domain_filename, "rb") as f: |
| 154 | + | try: |
| 155 | + | local_checksum = hashlib.md5(f.read()).hexdigest() |
| 156 | + | |
| 157 | + | if latest_checksum == local_checksum: |
| 158 | + | print("[*] You have the latest feeds\n") |
| 159 | + | # print("-> ", latest_checksum, " ", local_checksum) |
| 160 | + | return True |
| 161 | + | else: |
| 162 | + | # print("-> ", latest_checksum, " ", local_checksum) |
| 163 | + | return False |
| 164 | + | |
| 165 | + | except: |
| 166 | + | return False |
| 167 | + | return False |
| 168 | + | |
126 | 169 | | def download(self): |
127 | 170 | | """ |
128 | 171 | | Download the latest newly registered domains and save locally. |
| skipped 4 lines |
133 | 176 | | Return: |
134 | 177 | | none |
135 | 178 | | """ |
136 | | - | if self.period == "day": |
137 | | - | self.URL_file = "domain-names.txt" |
138 | | - | elif self.period == "week": |
139 | | - | self.URL_file = "domain-names-week.txt" |
140 | | - | elif self.period == "month": |
141 | | - | self.URL_file = "domain-names-month.txt" |
142 | | - | |
143 | 179 | | URL = self.URL + self.URL_file |
144 | 180 | | |
145 | | - | print("[*] Downloading fresh domain list from", URL) |
| 181 | + | print("[*] Downloading fresh domain list:", self.URL_file) |
146 | 182 | | |
147 | 183 | | # User-Agent |
148 | 184 | | ver = "openSquat-" + __VERSION__ |
| skipped 37 lines |
186 | 222 | | |
187 | 223 | | return True |
188 | 224 | | |
| 225 | + | def set_domain_filename(self, domain_filename): |
| 226 | + | """ |
| 227 | + | Method to set the domain filename. |
| 228 | + | |
| 229 | + | Args: |
| 230 | + | domain_filename |
| 231 | + | |
| 232 | + | Returns: |
| 233 | + | none |
| 234 | + | """ |
| 235 | + | if domain_filename == "": |
| 236 | + | self.domain_filename = "domain-names.txt" |
| 237 | + | else: |
| 238 | + | self.domain_filename = domain_filename |
| 239 | + | |
189 | 240 | | def set_filename(self, filename): |
190 | 241 | | """ |
191 | 242 | | Method to set the filename. |
| skipped 17 lines |
209 | 260 | | none |
210 | 261 | | """ |
211 | 262 | | self.period = search_period |
| 263 | + | |
| 264 | + | if self.period == "day": |
| 265 | + | self.URL_file = "domain-names.txt" |
| 266 | + | elif self.period == "week": |
| 267 | + | self.URL_file = "domain-names-week.txt" |
| 268 | + | elif self.period == "month": |
| 269 | + | self.URL_file = "domain-names-month.txt" |
212 | 270 | | |
213 | 271 | | def set_dns_validation(self, dns): |
214 | 272 | | """ |
| skipped 313 lines |
528 | 586 | | self.method = method |
529 | 587 | | |
530 | 588 | | if self.domain_filename == "": |
531 | | - | self.download() |
| 589 | + | self.domain_filename = self.URL_file |
| 590 | + | if not self.check_latest_feeds(): |
| 591 | + | self.download() |
532 | 592 | | |
533 | 593 | | self.count_files() |
534 | 594 | | self.read_files() |
| skipped 4 lines |