Created
November 7, 2017 09:56
-
-
Save neoplacer/04b05d3e5ef51fec62fdb72cd7d11490 to your computer and use it in GitHub Desktop.
Generate fake email addresses for spam harvesters
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""Generate fake email addresses for spam harvesters. | |
A pythonic Python port of Joerg Kantel's fakemail macro for Radio Userland. | |
It creates random e-mail addresses, optionally marked up as XHTML. | |
The ``prefix`` and ``postfix`` arguments were left out, since strings can | |
easily be prepended and appended, if needed. | |
For more information, see: | |
- http://www.schockwellenreiter.de/webworking/sonstiges/spam.html | |
- http://www.schockwellenreiter.de/ru/fakemail.html | |
- http://www.schockwellenreiter.de/images4/fakeMail.txt | |
:Copyright: 2006-2008 Jochen Kupperschmidt | |
:Date: 31-Aug-2008 | |
:License: MIT | |
""" | |
from itertools import islice | |
from random import choice, randint | |
from string import ascii_lowercase | |
# top-level domains | |
TLDS = ('com net org mil edu de biz de ch at ru de tv com' | |
'st br fr de nl dk ar jp eu it es com us ca pl').split() | |
def gen_name(length): | |
"""Generate a random name with the given number of characters.""" | |
return ''.join(choice(ascii_lowercase) for _ in xrange(length)) | |
def address_generator(): | |
"""Generate fake e-mail addresses.""" | |
while True: | |
user = gen_name(randint(3, 10)) | |
host = gen_name(randint(4, 20)) | |
yield '%s@%s.%s' % (user, host, choice(TLDS)) | |
def markup_address(address): | |
"""Wrap an e-mail address in an XHTML "mailto:" anchor.""" | |
return '<a href="mailto:%s">%s</a>' % ((address,) * 2) | |
def fake_addresses(count=20, sep=', ', markup=False): | |
"""Generate fake e-mail addresses. | |
If ``markup`` is true, turn the addresses into "mailto:" XHTML anchors. | |
""" | |
addresses = islice(address_generator(), count) | |
if markup: | |
addresses = map(markup_address, addresses) | |
return sep.join(addresses) | |
if __name__ == '__main__': | |
print fake_addresses(sep='\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment