banner
andrewji8

Being towards death

Heed not to the tree-rustling and leaf-lashing rain, Why not stroll along, whistle and sing under its rein. Lighter and better suited than horses are straw sandals and a bamboo staff, Who's afraid? A palm-leaf plaited cape provides enough to misty weather in life sustain. A thorny spring breeze sobers up the spirit, I feel a slight chill, The setting sun over the mountain offers greetings still. Looking back over the bleak passage survived, The return in time Shall not be affected by windswept rain or shine.
telegram
twitter
github

用 Python 能够算出身份证号码

开工。
先看看李大伟的朋友圈中发的图片。

image
车票中暴露的个人信息为:

3302211993****4914 李大伟

只缺少月份日期四位。

那么也就是一共 365 种可能。

科普时间:#

image
根据李大伟的身份证信息的前 6 位 “330221”

轻易可得:

image
浙江省宁波人,1993 年滴
那先用 python 生成 1993 年的所有日期吧.

import time

#生成出生当年所有日期
def dateRange(year):
    fmt = '%Y-%m-%d'
    bgn = int(time.mktime(time.strptime(year+'-01-01',fmt)))
    end = int(time.mktime(time.strptime(year+'-12-31',fmt)))
    list_date = [time.strftime(fmt,time.localtime(i)) for i in range(bgn,end+1,3600*24)]
    return [i.replace('-','') for i in list_date]

data_time  = dateRange('1993')

成功得到日期列表。

image

再用刚才的校验码计算规则反向验证哪个日期符合喽!自己写计算规则?
太麻烦!
给大家隆重介绍一个库:id-validator
安装:pip install id-validator
可以用来验证身份证号合法性、获取身份证号信息、生成可通过校验的假数据、身份证升级。

image
那么我们利用 id-validator 来依次校验刚才生成的身份证号码。完整代码如下:

from id_validator import validator
import time

#生成出生当年所有日期
def dateRange(year):
    fmt = '%Y-%m-%d'
    bgn = int(time.mktime(time.strptime(year+'-01-01', fmt)))
    end = int(time.mktime(time.strptime(year+'-12-31', fmt)))
    list_date = [time.strftime(fmt, time.localtime(i))for i in range(bgn, end+1, 3600*24)]
    return [i.replace('-', '') for i in list_date]

#遍历所有日期,print通过校验的身份证号码
def vali_dator(id1, id2, id3):
    for i in dateRange(id2):
        theid = id1 + i + id3
        if validator.is_valid(theid):
            print(theid)

vali_dator('330221','1993','4914')

运行结果:

image

如何在 33 个日期中挑出来李大伟的真实出生日期呢?
接下来就要通过身份证号码和姓名是否匹配来筛选最终的结果。以往的解决方案是:通过 12306 查询,在 12306 添加联系人,若身份证和姓名一致,就会显示校验通过。若不能通过,则说明身份证和姓名不一致。但现在这种方法已经不能用了。

然后我这里又找到了阿里云的实名认证接口,根据身份证姓名和身份证号码核对是身份信息是否一致。但只有企业用户才能使用,个人是没法用了,所以就不尝试了。

image

总结#

用 python 计算身份证号码的具体流程大概就是这样。当然出生月份和日期很多人都会在 QQ 或其它社交软件里面公开,一找就能找到。

加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。