Skip to content

Instantly share code, notes, and snippets.

@superkojiman
Last active February 11, 2026 05:06
Show Gist options
  • Select an option

  • Save superkojiman/11076951 to your computer and use it in GitHub Desktop.

Select an option

Save superkojiman/11076951 to your computer and use it in GitHub Desktop.

Revisions

  1. superkojiman revised this gist Mar 25, 2022. 1 changed file with 57 additions and 27 deletions.
    84 changes: 57 additions & 27 deletions namemash.py
    Original file line number Diff line number Diff line change
    @@ -1,36 +1,66 @@
    #!/usr/bin/env python
    #!/usr/bin/env python3

    '''
    NameMash by superkojiman
    Generate a list of possible usernames from a person's first and last name.
    https://blog.techorganic.com/2011/07/17/creating-a-user-name-list-for-brute-force-attacks/
    '''

    import sys
    import os.path

    if __name__ == "__main__":
    if __name__ == '__main__':
    if len(sys.argv) != 2:
    print("usage: {} names.txt".format((sys.argv[0])))
    print(f'usage: {sys.argv[0]} names.txt')
    sys.exit(0)

    if not os.path.exists(sys.argv[1]):
    print("{} not found".format(sys.argv[1]))
    print(f'{sys.argv[1]} not found')
    sys.exit(0)

    for line in open(sys.argv[1]):
    name = ''.join([c for c in line if c == " " or c.isalpha()])

    tokens = name.lower().split()

    # skip empty lines
    if len(tokens) < 1:
    continue

    fname = tokens[0]
    lname = tokens[-1]

    print(fname + lname) # johndoe
    print(lname + fname) # doejohn
    print(fname + "." + lname) # john.doe
    print(lname + "." + fname) # doe.john
    print(lname + fname[0]) # doej
    print(fname[0] + lname) # jdoe
    print(lname[0] + fname) # djoe
    print(fname[0] + "." + lname) # j.doe
    print(lname[0] + "." + fname) # d.john
    print(fname) # john
    print(lname) # joe
    with open(sys.argv[1]) as f:
    for line in enumerate(f):

    # remove anything in the name that aren't letters or spaces
    name = ''.join([c for c in line[1] if c == ' ' or c.isalpha()])
    tokens = name.lower().split()

    if len(tokens) < 1:
    # skip empty lines
    continue

    # assume tokens[0] is the first name
    fname = tokens[0]

    # remaining elements in tokens[] must be the last name
    lname = ''

    if len(tokens) == 2:
    # assume traditional first and last name
    # e.g. John Doe
    lname = tokens[-1]

    elif len(tokens) > 2:
    # assume multi-barrelled surname
    # e.g. Jane van Doe

    # remove the first name
    del tokens[0]

    # combine the multi-barrelled surname
    lname = ''.join([s for s in tokens])

    # create possible usernames
    print(fname + lname) # johndoe
    print(lname + fname) # doejohn
    print(fname + '.' + lname) # john.doe
    print(lname + '.' + fname) # doe.john
    print(lname + fname[0]) # doej
    print(fname[0] + lname) # jdoe
    print(lname[0] + fname) # djoe
    print(fname[0] + '.' + lname) # j.doe
    print(lname[0] + '.' + fname) # d.john
    print(fname) # john
    print(lname) # joe
  2. superkojiman revised this gist Apr 14, 2020. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions namemash.py
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,11 @@
    name = ''.join([c for c in line if c == " " or c.isalpha()])

    tokens = name.lower().split()

    # skip empty lines
    if len(tokens) < 1:
    continue

    fname = tokens[0]
    lname = tokens[-1]

  3. superkojiman revised this gist Apr 14, 2020. 1 changed file with 24 additions and 19 deletions.
    43 changes: 24 additions & 19 deletions namemash.py
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,31 @@
    #!/usr/bin/env python
    import sys
    import os.path

    if __name__ == "__main__":
    if len(sys.argv) != 2:
    print "usage: %s names.txt" % (sys.argv[0])
    sys.exit(0)
    if len(sys.argv) != 2:
    print("usage: {} names.txt".format((sys.argv[0])))
    sys.exit(0)

    for line in open(sys.argv[1]):
    name = ''.join([c for c in line if c == " " or c.isalpha()])
    if not os.path.exists(sys.argv[1]):
    print("{} not found".format(sys.argv[1]))
    sys.exit(0)

    tokens = name.lower().split()
    fname = tokens[0]
    lname = tokens[-1]
    for line in open(sys.argv[1]):
    name = ''.join([c for c in line if c == " " or c.isalpha()])

    print fname + lname # johndoe
    print lname + fname # doejohn
    print fname + "." + lname # john.doe
    print lname + "." + fname # doe.john
    print lname + fname[0] # doej
    print fname[0] + lname # jdoe
    print lname[0] + fname # djoe
    print fname[0] + "." + lname # j.doe
    print lname[0] + "." + fname # d.john
    print fname # john
    print lname # joe
    tokens = name.lower().split()
    fname = tokens[0]
    lname = tokens[-1]

    print(fname + lname) # johndoe
    print(lname + fname) # doejohn
    print(fname + "." + lname) # john.doe
    print(lname + "." + fname) # doe.john
    print(lname + fname[0]) # doej
    print(fname[0] + lname) # jdoe
    print(lname[0] + fname) # djoe
    print(fname[0] + "." + lname) # j.doe
    print(lname[0] + "." + fname) # d.john
    print(fname) # john
    print(lname) # joe
  4. superkojiman created this gist Apr 19, 2014.
    26 changes: 26 additions & 0 deletions namemash.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/usr/bin/env python
    import sys

    if __name__ == "__main__":
    if len(sys.argv) != 2:
    print "usage: %s names.txt" % (sys.argv[0])
    sys.exit(0)

    for line in open(sys.argv[1]):
    name = ''.join([c for c in line if c == " " or c.isalpha()])

    tokens = name.lower().split()
    fname = tokens[0]
    lname = tokens[-1]

    print fname + lname # johndoe
    print lname + fname # doejohn
    print fname + "." + lname # john.doe
    print lname + "." + fname # doe.john
    print lname + fname[0] # doej
    print fname[0] + lname # jdoe
    print lname[0] + fname # djoe
    print fname[0] + "." + lname # j.doe
    print lname[0] + "." + fname # d.john
    print fname # john
    print lname # joe