Skip to content

Commit

Permalink
Add Domain Generator Algorithm (DGA) by date
Browse files Browse the repository at this point in the history
  • Loading branch information
pishchalnikov committed Mar 19, 2020
1 parent d5123ba commit 44505cd
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions faker/providers/internet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,33 @@ def domain_word(self):
company = self._to_ascii(company_elements.pop(0))
return company

def dga(self, year=None, month=None, day=None, tld=None, length=None):
"""Generates a domain name by given date
https://en.wikipedia.org/wiki/Domain_generation_algorithm
:type year: int
:type month: int
:type day: int
:type tld: str
:type length: int
:rtype: str
"""

domain = ''
year = year or self.random_int(min=1, max=9999)
month = month or self.random_int(min=1, max=12)
day = day or self.random_int(min=1, max=30)
tld = tld or self.tld()
length = length or self.random_int(min=2, max=63)

for _ in range(length):
year = ((year ^ 8 * year) >> 11) ^ ((year & 0xFFFFFFF0) << 17)
month = ((month ^ 4 * month) >> 25) ^ 16 * (month & 0xFFFFFFF8)
day = ((day ^ (day << 13)) >> 19) ^ ((day & 0xFFFFFFFE) << 12)
domain += chr(((year ^ month ^ day) % 25) + 97)

return domain + '.' + tld

def tld(self):
return self.random_element(self.tlds)

Expand Down

0 comments on commit 44505cd

Please sign in to comment.