Python使用穷举法生成三大运营商的所有手机号码
import itertools as its
#定义手机号码段
num_start = ['133','149','153','170','173','177','180','181','189','199', #电信号码段
'130','131','132','145','155','156','166','171','175','176','185','186','166', # 联通号码段
'134','135','136','137','138','139','147','150','151','152','157','158','159','172','178','182','183','184','187','188','198'] #移动号码段
#定义写入函数
def writer(data):
with open('phone_num.txt','a',encoding='utf-8') as f:
f.write(data)
def main():
words = '1234567890' #定义数字
r = its.product(words,repeat=8) #穷举生成8位数字
for i in r:
a = ''.join(i)
for phone in num_start:
phone_num = phone + a #号码段+穷举数字生成手机号码
print(phone_num)
writer(phone_num + '\n') #写入文件
if __name__ == '__main__':
main()
print('全部手机号生成')
需要的时间有点久,可以添加多线程生成!!!!