diff --git a/README.md b/README.md
index bee7aff..c4cb8c3 100644
--- a/README.md
+++ b/README.md
@@ -1,88 +1,30 @@
-# profake
-python生成随机字符、中英文用户名、手机号、身份证等
-
---------
-
-### 自测试结果:
-
-```
-==========1.身份证号==========
-
-607036710724717
-
-992882199403012402
-
-261449199110098011
-
-38904119840102030X
-
-YES,15位身份证号正确!
-
-YES,18位身份证号正确!
-
-YES,18位身份证号正确!
-
-==========2.手机号==========
-
-13944898670
-
-13479416245
-
-13523563365
-
-==========3.随机数==========
-
-82
-
-69437243589733545059
-
-8340710961
-
-==========4.用户名==========
-
-于眉
-
-葛雁梁朗
-
-施中韵
-
-潘馥
-
-Fquplm
-
-Aaythunppybhhzbhiwff
-
-==========5.邮箱==========
-
-ab@J.J
-
-Iqi@S.S
-
-0@qq.com
-
-DS@qq.com
-
-m@sina.com
-
-zbFDQqBr@f.f
-
-W@B.B
-
-参数过小,无法生成!
-
-EKMdPQUgs@s.s
-
-zOTdCYg@qq.com
-
-==========5.IP地址==========
-
-24.201.108.4
-
-192.30.25.44
-
-192.168.74.78
-
-192.168.136.97
-
-```
+#profake
+python生成随机字符、中英文用户名、手机号、身份证等
+
+test ok : python 3.7
+Usage:
+
+from fake_modules.utils.tools import *
+from fake_modules.fake_email import email
+from fake_modules.fake_id import make_id,check_id
+from fake_modules.fake_ip import ip
+from fake_modules.fake_name import name
+from fake_modules.fake_number import number
+from fake_modules.fake_phone import phone
+
+├── fake_modules
+│ ├── fake_email.py
+│ ├── fake_id.py
+│ ├── fake_ip.py
+│ ├── fake_name.py
+│ ├── fake_number.py
+│ ├── fake_phone.py
+│ ├── __init__.py
+│ └── utils
+│ ├── __init__.py
+│ └── tools.py
+├── __init__.py
+└── README.md
+
+2 directories, 11 files
diff --git a/__init__.py b/__init__.py
new file mode 100644
index 0000000..f5c8200
--- /dev/null
+++ b/__init__.py
@@ -0,0 +1,9 @@
+#!/usr/bin/python3
+
+from fake_modules.utils.tools import *
+from fake_modules.fake_email import email
+from fake_modules.fake_id import make_id,check_id
+from fake_modules.fake_ip import ip
+from fake_modules.fake_name import name
+from fake_modules.fake_number import number
+from fake_modules.fake_phone import phone
diff --git a/fake_modules/__init__.py b/fake_modules/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/fake_modules/__pycache__/__init__.cpython-37.pyc b/fake_modules/__pycache__/__init__.cpython-37.pyc
new file mode 100644
index 0000000..b4acc57
Binary files /dev/null and b/fake_modules/__pycache__/__init__.cpython-37.pyc differ
diff --git a/fake_modules/__pycache__/fake_email.cpython-37.pyc b/fake_modules/__pycache__/fake_email.cpython-37.pyc
new file mode 100644
index 0000000..204631c
Binary files /dev/null and b/fake_modules/__pycache__/fake_email.cpython-37.pyc differ
diff --git a/fake_modules/__pycache__/fake_id.cpython-37.pyc b/fake_modules/__pycache__/fake_id.cpython-37.pyc
new file mode 100644
index 0000000..9b3ef53
Binary files /dev/null and b/fake_modules/__pycache__/fake_id.cpython-37.pyc differ
diff --git a/fake_modules/__pycache__/fake_ip.cpython-37.pyc b/fake_modules/__pycache__/fake_ip.cpython-37.pyc
new file mode 100644
index 0000000..45cedb1
Binary files /dev/null and b/fake_modules/__pycache__/fake_ip.cpython-37.pyc differ
diff --git a/fake_modules/__pycache__/fake_name.cpython-37.pyc b/fake_modules/__pycache__/fake_name.cpython-37.pyc
new file mode 100644
index 0000000..d6249f3
Binary files /dev/null and b/fake_modules/__pycache__/fake_name.cpython-37.pyc differ
diff --git a/fake_modules/__pycache__/fake_number.cpython-37.pyc b/fake_modules/__pycache__/fake_number.cpython-37.pyc
new file mode 100644
index 0000000..7c5877b
Binary files /dev/null and b/fake_modules/__pycache__/fake_number.cpython-37.pyc differ
diff --git a/fake_modules/__pycache__/fake_phone.cpython-37.pyc b/fake_modules/__pycache__/fake_phone.cpython-37.pyc
new file mode 100644
index 0000000..cb5d8ba
Binary files /dev/null and b/fake_modules/__pycache__/fake_phone.cpython-37.pyc differ
diff --git a/fake_modules/fake_email.py b/fake_modules/fake_email.py
new file mode 100644
index 0000000..5f35d61
--- /dev/null
+++ b/fake_modules/fake_email.py
@@ -0,0 +1,36 @@
+import random
+import string
+from fake_modules.utils.tools import get_number,get_lowercase,get_letter,get_mix
+
+def _email():
+ """生成邮箱地址"""
+ array1 = ['126.com', '163.com', 'sina.com', 'sohu.com', 'yahoo.com.cn', 'gmail.com','yahoo.com']
+ array2 = ['qq.com']
+
+ array = random.choice([array1,array2])
+ address = random.choice(array)
+ if array == array2:
+ salt = get_number(9)
+ if salt.startswith('0'):
+ user = '1' + salt
+ else:
+ user = salt
+ else:
+ user = get_lowercase(random.randint(6,10))
+
+ fake_email = user + '@' + address
+ return fake_email
+
+def email(n=1):
+ '''
+ 生成随机邮箱
+ n = 1 return str
+ n > 1 return list for str
+ '''
+ s = []
+ for i in range(n):
+ s.append(_email())
+ if len(s) == 1:
+ return s[0]
+ else:
+ return s
diff --git a/fake_modules/fake_id.py b/fake_modules/fake_id.py
new file mode 100644
index 0000000..c1088b1
--- /dev/null
+++ b/fake_modules/fake_id.py
@@ -0,0 +1,49 @@
+import random
+import string
+import time
+
+def make_id():
+ """随机生成18为身份证"""
+ ARR = (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2)
+ LAST = ('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2')
+ t = time.localtime()[0] # 年份
+ k = '{:0>2}{:0>2}{:0>2}{:0>4}{:0>2}{:0>2}{:0>3}'.format(random.randint(10, 99),
+ random.randint(1, 99),
+ random.randint(1, 99),
+ random.randint(t - 80, t - 18),
+ random.randint(1, 12),
+ random.randint(1, 28),
+ random.randint(1, 999))
+ y = 0
+ for i in range(17):
+ y += int(k[i]) * ARR[i]
+ return '%s%s' % (k, LAST[y % 11])
+
+def check_id(ID):
+ '''
+ 检查身份证是不是符合要求 ARP为每个数字的权重
+ '''
+ ARR = (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2)
+ LAST = ('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2')
+ xlen = len(str(ID))
+ if xlen != 18:
+ return False
+ try:
+ if xlen == 18:
+ x2 = ID[6:14]
+ x3 = time.strptime(x2, '%Y%m%d')
+ if x2 < '19000101' or x3 > time.localtime():
+ return False
+ else:
+ x2 = time.strptime(ID[6:12], '%y%m%d')
+ except:
+ return False
+ if xlen == 18:
+ y = 0
+ for i in range(17):
+ y += int(ID[i]) * ARR[i]
+
+ if LAST[y % 11] != ID[-1].upper():
+ return False
+ return True
+
diff --git a/fake_modules/fake_ip.py b/fake_modules/fake_ip.py
new file mode 100644
index 0000000..2069518
--- /dev/null
+++ b/fake_modules/fake_ip.py
@@ -0,0 +1,18 @@
+import random
+import string
+
+
+def _ip():
+
+ return '{}.{}.{}.{}'.format(random.randint(0,255),random.randint(0,255),random.randint(0,255),random.randint(0,255))
+
+def ip(n=1):
+
+ s = []
+ for i in range(n):
+ s.append(_ip())
+
+ if n == 1:
+ return s[0]
+ else:
+ return s
diff --git a/fake_modules/fake_name.py b/fake_modules/fake_name.py
new file mode 100644
index 0000000..e5876e0
--- /dev/null
+++ b/fake_modules/fake_name.py
@@ -0,0 +1,45 @@
+import random
+
+def name(Language='cn', count=2):
+ """生成随机用户名,参数Language为中文用户或英文用户,参数count为用户名位数"""
+ if Language.lower() == 'cn':
+ array1 = ['赵', '钱', '孙', '李', '周', '吴', '郑', '王', '冯', '陈', '褚', '卫', '蒋', '沈', '韩', '杨', '朱',
+ '秦', '尤', '许', '何', '吕', '施', '张', '孔', '曹', '严', '华', '金', '魏', '陶', '姜', '戚', '谢',
+ '邹', '喻', '柏', '水', '窦', '章', '云', '苏', '潘', '葛', '奚', '范', '彭', '郎', '鲁', '韦', '昌',
+ '马', '苗', '凤', '花', '方', '俞', '任', '袁', '柳', '酆', '鲍', '史', '唐', '费', '廉', '岑', '薛',
+ '雷', '贺', '倪', '汤', '滕', '殷', '罗', '毕', '郝', '邬', '安', '常', '乐', '于', '时', '傅', '皮',
+ '卞', '齐', '康', '伍', '余', '元', '卜', '顾', '孟', '平', '黄', '和', '穆', '萧', '尹', '姚', '邵',
+ '堪', '汪', '祁', '毛', '禹', '狄', '米', '贝', '明', '臧', '计', '伏', '成', '戴', '谈', '宋', '茅',
+ '庞', '熊', '纪', '舒', '屈', '项', '祝', '董', '梁']
+ array2 = ['秀', '娟', '英', '华', '慧', '巧', '美', '娜', '静', '淑', '惠', '珠', '翠', '雅', '玉', '萍', '红',
+ '娥', '玲', '芬', '芳', '燕', '彩', '春', '菊', '兰', '凤', '梅', '琳', '素', '云', '莲', '真', '环',
+ '雪', '荣', '爱', '妹', '霞', '香', '莺', '媛', '艳', '瑞', '凡', '佳', '嘉', '琼', '勤', '珍', '贞',
+ '莉', '桂', '叶', '璧', '璐', '娅', '琦', '晶', '妍', '茜', '秋', '珊', '莎', '锦', '黛', '倩', '婷',
+ '姣', '婉', '娴', '瑾', '颖', '露', '瑶', '怡', '婵', '雁', '蓓', '仪', '荷', '丹', '蓉', '眉', '君',
+ '琴', '蕊', '薇', '菁', '梦', '岚', '苑', '柔', '竹', '霭', '凝', '晓', '欢', '霄', '枫', '芸', '菲',
+ '寒', '欣', '滢', '伊', '亚', '宜', '可', '姬', '舒', '影', '荔', '枝', '思', '丽', '秀', '飘', '育',
+ '馥', '琦', '晶', '妍', '茜', '秋', '珊', '莎', '锦', '黛', '青', '倩', '婷', '宁', '蓓', '纨', '苑',
+ '婕', '馨', '瑗', '琰', '韵', '融', '园', '艺', '咏', '卿', '聪', '澜', '纯', '毓', '悦', '昭', '冰',
+ '爽', '琬', '茗', '羽', '希', '伟', '刚', '勇', '毅', '俊', '峰', '强', '军', '平', '保', '东', '文',
+ '辉', '明', '永', '健', '世', '广', '志', '义', '兴', '良', '海', '山', '仁', '波', '贵', '福', '生',
+ '龙', '元', '全', '国', '胜', '学', '祥', '才', '发', '武', '新', '清', '飞', '彬', '富', '顺', '信',
+ '子', '杰', '涛', '昌', '成', '康', '星', '天', '达', '安', '岩', '中', '茂', '进', '林', '有', '坚',
+ '和', '彪', '诚', '先', '敬', '震', '振', '壮', '会', '思', '群', '豪', '心', '邦', '承', '乐', '功',
+ '松', '善', '厚', '庆', '磊', '民', '友', '裕', '河', '哲', '江', '超', '亮', '政', '谦', '亨', '奇',
+ '固', '之', '轮', '翰', '朗', '伯', '宏', '言', '鸣', '朋', '斌', '梁', '栋', '维', '启', '克', '伦',
+ '翔', '旭', '鹏', '泽', '辰', '士', '以', '建', '家', '致', '树', '炎', '德', '行', '时', '泰', '盛']
+ front = array1[random.randint(0, len(array1) - 1)]
+ last = ''
+ for i in range(count - 1):
+ last = last + array2[random.randint(0, len(array2) - 1)]
+ return '{}{}'.format(front,last)
+ elif Language.lower() == 'en':
+ array3 = ['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h',
+ 'g', 'f', 'e', 'd', 'c', 'b', 'a']
+ enName = ''
+ for i in range(count):
+ enName = enName + array3[random.randint(0, len(array3) - 1)]
+ return enName.capitalize()
+ else:
+ return False
+
diff --git a/fake_modules/fake_number.py b/fake_modules/fake_number.py
new file mode 100644
index 0000000..7c9872d
--- /dev/null
+++ b/fake_modules/fake_number.py
@@ -0,0 +1,6 @@
+import random
+from fake_modules.utils.tools import get_number
+
+def number(n=10):
+ return get_number(n)
+
diff --git a/fake_modules/fake_phone.py b/fake_modules/fake_phone.py
new file mode 100644
index 0000000..1034069
--- /dev/null
+++ b/fake_modules/fake_phone.py
@@ -0,0 +1,22 @@
+import random
+import requests
+import socket
+import string
+import time
+
+def phone(status=0):
+ """生成手机号,参数status为状态,1或其它值代表在线验证后的结果,0表示离线生成的结果"""
+ while True:
+ phone = random.choice(['134','135','136','137','138','139','150','151','152','157','158','159','187','188','130','131','132','155','156','185','186','133','153','180','189']) + ''.join(random.choice('0123456789') for i in range(8))
+ if status == 0:
+ return phone
+ else:
+ status += 1
+ try:
+ r = requests.get('http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=' + phone, timeout=2)
+ obj = eval(r.text.split('=')[1], type('Dummy', (dict,), dict(__getitem__=lambda s, n: n))())
+ if obj['telString'] == str(phone):
+ return phone
+ except:
+ if status >= 6:
+ return phone
diff --git a/fake_modules/utils/__init__.py b/fake_modules/utils/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/fake_modules/utils/__pycache__/__init__.cpython-37.pyc b/fake_modules/utils/__pycache__/__init__.cpython-37.pyc
new file mode 100644
index 0000000..b933333
Binary files /dev/null and b/fake_modules/utils/__pycache__/__init__.cpython-37.pyc differ
diff --git a/fake_modules/utils/__pycache__/tools.cpython-37.pyc b/fake_modules/utils/__pycache__/tools.cpython-37.pyc
new file mode 100644
index 0000000..ec67ed1
Binary files /dev/null and b/fake_modules/utils/__pycache__/tools.cpython-37.pyc differ
diff --git a/fake_modules/utils/tools.py b/fake_modules/utils/tools.py
new file mode 100644
index 0000000..10cd21b
--- /dev/null
+++ b/fake_modules/utils/tools.py
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+# some functions
+import string
+import random
+
+def random_number():
+ return random.choice(string.digits)
+
+def random_lowercase():
+ return random.choice(string.ascii_lowercase)
+
+def random_uppercase():
+ return random.choice(string.ascii_uppercase)
+
+def random_lettercase():
+ return random.choice(string.ascii_letters)
+
+def random_all():
+ return random.choice(string.ascii_lowercase+string.digits)
+
+def get_number(n=10):
+ s = ''
+ for i in range(n):
+ s += random_number()
+ return s
+
+def get_lowercase(n=10):
+ s = ''
+ for i in range(n):
+ s += random_lowercase()
+ return s
+
+def get_letter(n=10):
+ s = ''
+ for i in range(n):
+ s += random_lettercase()
+ return s
+
+def get_mix(n=10):
+ s = ''
+ for i in range(n):
+ s += random_all()
+ return s
+
diff --git a/profaker.py b/profaker.py
deleted file mode 100644
index 63de7ef..0000000
--- a/profaker.py
+++ /dev/null
@@ -1,324 +0,0 @@
-# -*- coding: utf-8 -*-
-
-"""
-根据需要生成随机仿真内容,如身份证,手机号,邮箱地址等
-需要安装requests 可使用pip install requests方式快速安装,或屏蔽在线验证手机号代码
-"""
-import random
-import requests
-import socket
-import string
-import struct
-import time
-
-'''''''''''''''
-1.生成和效验身份证
-'''''''''''''''
-def makeID18():
- u"""随机生成18为身份证"""
- ARR = (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2)
- LAST = ('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2')
- t = time.localtime()[0] # 年份
- k = '%02d%02d%02d%04d%02d%02d%03d' % (random.randint(10, 99),
- random.randint(01, 99),
- random.randint(01, 99),
- random.randint(t - 80, t - 18),
- random.randint(1, 12),
- random.randint(1, 28),
- random.randint(1, 999))
- y = 0
- for i in range(17):
- y += int(k[i]) * ARR[i]
- return '%s%s' % (k, LAST[y % 11])
-
-
-def MakeID(count, x=''):
- u"""生成15或18位身份证,参数count为位数,x为获取结尾为x的身份证"""
- if str(count) == '15':
- u'''生成15位身份证'''
- strID = makeID18()
- # logger.Success('makeID15:ok')
- return strID[0:6] + strID[8:17]
- elif str(count) == '18' and x != '':
- while True:
- strX = makeID18()
- if strX[17:18] == str(x).upper():
- # logger.Success('makeID18+X:ok')
- return strX
- elif str(count) == '18':
- return makeID18()
- # logger.Error('参数错误!')
- return u'参数错误!'
-
-
-def CheckID(ID):
- u"""效验身份证号码,参数ID为15或18位身份证号"""
- ARR = (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2)
- LAST = ('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2')
- xlen = len(ID)
- if xlen != 18 and xlen != 15:
- # logger.Error('CheckID:身份证号码长度错误!')
- return u'身份证号码长度错误!'
- try:
- if xlen == 18:
- x2 = ID[6:14]
- x3 = time.strptime(x2, '%Y%m%d')
- if x2 < '19000101' or x3 > time.localtime():
- # logger.Error('CheckID:身份证出生时间错误,超过允许的时间范围!')
- return u'身份证出生时间错误,超过允许的时间范围!'
- else:
- x2 = time.strptime(ID[6:12], '%y%m%d')
- except:
- # logger.Error('CheckID:身份证出生时间错误,非合法时间!')
- return u'CheckID:身份证出生时间错误,非合法时间!'
- if xlen == 18:
- y = 0
- for i in range(17):
- y += int(ID[i]) * ARR[i]
-
- if LAST[y % 11] != ID[-1].upper():
- # logger.Error('CheckID:身份证效验码错误!')
- return u'身份证效验码错误!'
- # logger.Success('CheckID:ok')
- return u'YES,' + str(xlen) + u'位身份证号正确!'
-
-
-def IDoldToNew(ID):
- u"""15位身份证号转18位身份证号,参数count为15位身份证"""
- ARR = (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2)
- LAST = ('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2')
- if len(ID) != 15:
- # logger.Error('IDoldToNew:身份证号码输入错误,身份证号码长度不为15位')
- return u'身份证号码输入错误,身份证号码长度不为15位'
- oldcard = '%s19%s' % (ID[:6], ID[6:])
- y = 0
- for i in range(17):
- y += int(oldcard[i]) * ARR[i]
- # logger.Success('IDoldToNew:ok')
- return '%s%s' % (oldcard, LAST[y % 11])
-
-
-'''''''''''''''
-2.生成手机号
-'''''''''''''''
-def MakePhone(status=0):
- u"""生成手机号,参数status为状态,1或其它值代表在线验证后的结果,0表示离线生成的结果"""
- while True:
- phone = random.choice(['134','135','136','137','138','139','150','151','152','157','158','159','187','188','130','131','132','155','156','185','186','133','153','180','189']) + ''.join(random.choice('0123456789') for i in range(8))
- if status == 0:
- # 无网络环境情况 ,但会出现少量不正确的手机号
- # logger.Success('MakePhone:offline ok')
- return phone
- else:
- # 为确保手机号正确,调用第三方接口进行验证
- status += 1
- try:
- r = requests.get('http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=' + phone, timeout=2)
- # print r.status_code #返回值200为正确
- obj = eval(r.text.split('=')[1], type('Dummy', (dict,), dict(__getitem__=lambda s, n: n))())
- if obj['telString'] == str(phone):
- # logger.Success('MakePhone:online ok')
- return phone
- except:
- if status >= 6:
- # 尝试连接验证手机号大于5次后,不再进行验证,直接返回随机值
- # logger.Success('MakePhone:网络异常!直接返回offline手机号!')
- return phone
- # logger.Success('MakePhone:手机号验证不通过,或网络异常!')
-
-
-'''''''''''''''
-3.生成指定长度的随机数
-'''''''''''''''
-def MakeNum(count=10):
- u"""指定长度随机数,参数count为位数,默认10"""
- num = int(str(random.random()).split('.')[1])
- while len(str(num)) < count:
- num = num * num
- # logger.Success('MakeNum:ok')
- return str(num)[0:count]
-
-
-'''''''''''''''
-4.生成随机用户名,包括中文用户和英文用户,参数为位数
-'''''''''''''''
-def MakeUser(Language='cn', count=2):
- u"""生成随机用户名,参数Language为中文用户或英文用户,参数count为用户名位数"""
- if Language.lower() == 'cn':
- array1 = ['赵', '钱', '孙', '李', '周', '吴', '郑', '王', '冯', '陈', '褚', '卫', '蒋', '沈', '韩', '杨', '朱',
- '秦', '尤', '许', '何', '吕', '施', '张', '孔', '曹', '严', '华', '金', '魏', '陶', '姜', '戚', '谢',
- '邹', '喻', '柏', '水', '窦', '章', '云', '苏', '潘', '葛', '奚', '范', '彭', '郎', '鲁', '韦', '昌',
- '马', '苗', '凤', '花', '方', '俞', '任', '袁', '柳', '酆', '鲍', '史', '唐', '费', '廉', '岑', '薛',
- '雷', '贺', '倪', '汤', '滕', '殷', '罗', '毕', '郝', '邬', '安', '常', '乐', '于', '时', '傅', '皮',
- '卞', '齐', '康', '伍', '余', '元', '卜', '顾', '孟', '平', '黄', '和', '穆', '萧', '尹', '姚', '邵',
- '堪', '汪', '祁', '毛', '禹', '狄', '米', '贝', '明', '臧', '计', '伏', '成', '戴', '谈', '宋', '茅',
- '庞', '熊', '纪', '舒', '屈', '项', '祝', '董', '梁']
- array2 = ['秀', '娟', '英', '华', '慧', '巧', '美', '娜', '静', '淑', '惠', '珠', '翠', '雅', '玉', '萍', '红',
- '娥', '玲', '芬', '芳', '燕', '彩', '春', '菊', '兰', '凤', '梅', '琳', '素', '云', '莲', '真', '环',
- '雪', '荣', '爱', '妹', '霞', '香', '莺', '媛', '艳', '瑞', '凡', '佳', '嘉', '琼', '勤', '珍', '贞',
- '莉', '桂', '叶', '璧', '璐', '娅', '琦', '晶', '妍', '茜', '秋', '珊', '莎', '锦', '黛', '倩', '婷',
- '姣', '婉', '娴', '瑾', '颖', '露', '瑶', '怡', '婵', '雁', '蓓', '仪', '荷', '丹', '蓉', '眉', '君',
- '琴', '蕊', '薇', '菁', '梦', '岚', '苑', '柔', '竹', '霭', '凝', '晓', '欢', '霄', '枫', '芸', '菲',
- '寒', '欣', '滢', '伊', '亚', '宜', '可', '姬', '舒', '影', '荔', '枝', '思', '丽', '秀', '飘', '育',
- '馥', '琦', '晶', '妍', '茜', '秋', '珊', '莎', '锦', '黛', '青', '倩', '婷', '宁', '蓓', '纨', '苑',
- '婕', '馨', '瑗', '琰', '韵', '融', '园', '艺', '咏', '卿', '聪', '澜', '纯', '毓', '悦', '昭', '冰',
- '爽', '琬', '茗', '羽', '希', '伟', '刚', '勇', '毅', '俊', '峰', '强', '军', '平', '保', '东', '文',
- '辉', '明', '永', '健', '世', '广', '志', '义', '兴', '良', '海', '山', '仁', '波', '贵', '福', '生',
- '龙', '元', '全', '国', '胜', '学', '祥', '才', '发', '武', '新', '清', '飞', '彬', '富', '顺', '信',
- '子', '杰', '涛', '昌', '成', '康', '星', '天', '达', '安', '岩', '中', '茂', '进', '林', '有', '坚',
- '和', '彪', '诚', '先', '敬', '震', '振', '壮', '会', '思', '群', '豪', '心', '邦', '承', '乐', '功',
- '松', '善', '厚', '庆', '磊', '民', '友', '裕', '河', '哲', '江', '超', '亮', '政', '谦', '亨', '奇',
- '固', '之', '轮', '翰', '朗', '伯', '宏', '言', '鸣', '朋', '斌', '梁', '栋', '维', '启', '克', '伦',
- '翔', '旭', '鹏', '泽', '辰', '士', '以', '建', '家', '致', '树', '炎', '德', '行', '时', '泰', '盛']
- front = array1[random.randint(0, len(array1) - 1)]
- last = ''
- for i in range(count - 1):
- last = last + array2[random.randint(0, len(array2) - 1)]
- # logger.Success('MakeUser:cn username ok')
- return "%s%s" % (front.decode("utf-8"),last.decode("utf-8"))
- elif Language.lower() == 'en':
- array3 = ['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h',
- 'g', 'f', 'e', 'd', 'c', 'b', 'a']
- enName = ''
- for i in range(count):
- enName = enName + array3[random.randint(0, len(array3) - 1)]
- # logger.Success('MakeUser:en username ok')
- return enName.capitalize()
- else:
- # logger.Error('MakeUser:参数错误!')
- return '参数错误!'
-
-
-'''''''''''''''
-5.生成随机邮箱地址
-'''''''''''''''
-def MakeMail(count=12):
- u"""生成邮箱地址,参数count为邮箱位数,如参数过小,直接输出最短邮箱,例如:a@a.a"""
- array1 = ['@126.com', '@163.com', '@sina.com', '@sohu.com', '@yahoo.com.cn', '@qq.com', '@bjca.org.cn']
- last = array1[random.randint(0, len(array1) - 1)]
- if count < 5:
- # logger.Error('MakeMail:参数过小,无法生成!')
- return u'参数过小,无法生成!'
- elif count == 8:
- try:
- last = '@qq.com'
- salt = ''.join(random.sample(string.ascii_letters + string.digits, int(count - len(last))))
- # logger.Success('MakeMail:ok')
- return salt + last
- except:
- # logger.Error('MakeMail:执行异常!')
- return u'执行异常!'
- elif count == 9:
- try:
- last = random.choice(['@qq.com', '@163.com', '@126.com'])
- salt = ''.join(random.sample(string.ascii_letters + string.digits, int(count - len(last))))
- # logger.Success('MakeMail:ok')
- return salt + last
- except:
- # logger.Error('MakeMail:执行异常!')
- return u'执行异常!'
- elif count >= 10 | count <= 13:
- try:
- last = random.choice(['@qq.com', '@163.com', '@126.com', '@sina.com', '@sohu.com'])
- salt = ''.join(random.sample(string.ascii_letters + string.digits, int(count - len(last))))
- # logger.Success('MakeMail:ok')
- return salt + last
- except:
- # logger.Error('MakeMail:执行异常!')
- return u'执行异常!'
- elif count > 13:
- try:
- salt = ''.join(random.sample(string.ascii_letters + string.digits, int(count - len(last))))
- # logger.Success('MakeMail:ok')
- return salt + last
- except:
- # logger.Error('MakeMail:执行异常!')
- return u'执行异常!'
- else:
- salt1 = ''.join(random.sample(string.ascii_letters, 1))
- salt2 = ''.join(random.sample(string.ascii_letters, count - 4))
- # logger.Success('MakeMail:ok')
- return salt2 + '@' + salt1 + '.' + salt1
-
-
-'''''''''''''''
-5.生成IP地址
-'''''''''''''''
-def MakeIP(count=''):
- u"""
- 无参数时,全部随机,count参数可指定ip一,二,三位,
- 例如:count='192'
- count='192.168'
- count='192.168.136'
- """
- begin1 = begin2 = begin3 = 0
- end1 = end2 = end3 = 255
- ip = count.split('.')
- try:
- if ip[0] != '':
- end1 = begin1 = int(ip[0])
- if ip[1] != '':
- end2 = begin2 = int(ip[1])
- if ip[2] != '':
- end3 = begin3 = int(ip[2])
- except:
- pass
- # logger.Error('未输入参数或参数错误!')
- try:
- # logger.Success('MakeIP:ok')
- # inet_pton()支持IPV6;inet_ntoa仅支持IPV4
- return socket.inet_ntoa(struct.pack('>I', random.randint(begin1 * 16777216 + begin2 * 65536 + begin3 * 256,
- end1 * 16777216 + end2 * 65536 + end3 * 256 + 255)))
- except:
- # logger.Error('参数输入错误!')
- return u'参数输入错误!'
-
-
-'''''''''''''''
-全部测试内容
-'''''''''''''''
-def test():
- print u'==========1.身份证号=========='
- print MakeID(15)
- print MakeID(18)
- print MakeID(18, 1) # 生成位数为1的身份证号
- print MakeID(18, 'X') # 生成位数为X的身份证号
- print CheckID(MakeID(15))
- print CheckID(MakeID(18))
- print CheckID(IDoldToNew(MakeID(15)))
- print u'==========2.手机号=========='
- print MakePhone(0)
- print MakePhone(1)
- print MakePhone()
- print u'==========3.随机数=========='
- print MakeNum(2) # 3位随机数
- print MakeNum(20) # 20位随机数
- print MakeNum()
- print u'==========4.用户名=========='
- print MakeUser()
- print MakeUser('Cn', 4)
- print MakeUser('cN', 3)
- print MakeUser('cn', 2)
- print MakeUser('EN', 6)
- print MakeUser('en', 20)
- print u'==========5.邮箱=========='
- print MakeMail(6)
- print MakeMail(7)
- print MakeMail(8)
- print MakeMail(9)
- print MakeMail(10)
- print MakeMail()
- print MakeMail(5)
- print MakeMail(4)
- print MakeMail(13)
- print MakeMail(14)
- print u'==========5.IP地址=========='
- print MakeIP()
- print MakeIP('192')
- print MakeIP('192.168')
- print MakeIP('192.168.136')
-
-
-if __name__ == '__main__':
- test()
- #print CheckID("871662191607071315")
diff --git a/test.py b/test.py
new file mode 100644
index 0000000..8d15c33
--- /dev/null
+++ b/test.py
@@ -0,0 +1,48 @@
+#!/usr/bin/python3
+
+import unittest
+
+from fake_modules.fake_email import email
+from fake_modules.fake_id import make_id,check_id
+from fake_modules.fake_ip import ip
+from fake_modules.fake_name import name
+from fake_modules.fake_number import number
+from fake_modules.fake_phone import phone
+
+class testProfaker(unittest.TestCase):
+
+ def setUp(self):
+
+ pass
+
+ def test_email(self):
+
+ self.assertTrue(email(),'email error')
+ self.assertTrue(email(10),'email n error')
+
+ def test_make_id(self):
+
+ self.assertTrue(make_id(),'make id error')
+ self.assertTrue(check_id(make_id()),'checkid error')
+ self.assertFalse(check_id(123),'checkid error')
+
+ def test_ip(self):
+
+ self.assertTrue(ip(),'ip error')
+
+ def test_name(self):
+
+ self.assertTrue(name(),'name error')
+
+ def test_number(self):
+
+ self.assertTrue(number(),'number error')
+ self.assertEqual(11,len(number(11)),'number error')
+
+ def test_phone(self):
+
+ self.assertTrue(phone(),'phone error')
+
+
+if __name__ == '__main__':
+ unittest.main()