#!/usr/bin/python
"""
FoneyGen: Generate a list of all potential usable US phone numbers
following North American Numbering Plan rules.
Author: Daniel Smith (https://github.com/ifnull/)
Usage:
foneygen.py area-codes
foneygen.py phone-numbers --npa <argument>
Options:
-h --help Show this screen.
--version Show version.
--npa=<npa> Specify area code.
"""
from docopt import docopt
def main():
arguments = docopt(__doc__, version='FoneyGen 0.1')
if arguments['area-codes'] is True:
npas = generate_npas()
for i in npas:
print i
if arguments['phone-numbers'] is True:
npa = arguments['--npa']
pns = generate_phone_numbers(npa)
for i in pns:
print i
def generate_npas():
"""
NPA (Area Code) Rules:
http://www.nanpa.com/area_codes/index.html
* Starts with [2-9].
* Does not end in 11 (N11).
* Does not end in 9* (N9X).
* Does not start with 37 (37X).
* Does not start with 96 (96X).
* Does not contain ERC (Easily Recognizable
Codes) AKA last two digits aren't the same.
"""
npa = []
for x in range(200, 1000):
s = str(x)
# N11
if s[1:] == '11':
continue
# N9X
if s[1:-1] == '9':
continue
# 37X/96X
if s[:2] == '37' or s[:2] == '96':
continue
# ERC
if s[1:2] == s[2:3]:
continue
npa.append(x)
return npa
def generate_cos():
"""
CO (Prefix) Rules:
* Starts with [2-9].
* Does not end with 11 (N11).
"""
co = []
for x in range(200, 1000):
s = str(x)
# N11
if s[1:] == '11':
continue
co.append(x)
return co
def generate_phone_numbers(npa):
pns = []
for co in generate_cos():
for sub in range(1, 10000):
sub = "%04d" % sub
pn = '{0}{1}{2}'.format(npa, co, sub)
pns.append(pn)
return pns
if __name__ == "__main__":
main()