{"id":13814196,"url":"https://github.com/gh0stkey/RGPerson","last_synced_at":"2025-05-15T03:33:08.615Z","repository":{"id":43496468,"uuid":"202105456","full_name":"gh0stkey/RGPerson","owner":"gh0stkey","description":"RGPerson - Randomly generate identity information","archived":false,"fork":false,"pushed_at":"2021-08-19T10:49:23.000Z","size":113,"stargazers_count":482,"open_issues_count":0,"forks_count":84,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-10-18T13:15:21.475Z","etag":null,"topics":["python"],"latest_commit_sha":null,"homepage":"https://gh0st.cn/RGPerson","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gh0stkey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-13T09:02:11.000Z","updated_at":"2024-10-14T05:55:39.000Z","dependencies_parsed_at":"2022-08-03T00:01:34.985Z","dependency_job_id":null,"html_url":"https://github.com/gh0stkey/RGPerson","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gh0stkey%2FRGPerson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gh0stkey%2FRGPerson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gh0stkey%2FRGPerson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gh0stkey%2FRGPerson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gh0stkey","download_url":"https://codeload.github.com/gh0stkey/RGPerson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225326416,"owners_count":17456936,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python"],"created_at":"2024-08-04T04:01:46.718Z","updated_at":"2024-11-19T09:30:28.331Z","avatar_url":"https://github.com/gh0stkey.png","language":"HTML","funding_links":[],"categories":["HTML","Python (1887)","Python"],"sub_categories":[],"readme":"# RGPerson\n\n项目地址：[https://github.com/gh0stkey/RGPerson](https://github.com/gh0stkey/RGPerson)\n\nRGPerson - 随机身份生成\n\n环境：python3\n\n使用方法：python3 RGPerson.py\n\n## 为什么需要Ta\n\n相信很多师傅们在做测试的时候经常遇到一些注册的业务功能，要填写的东西很多，我一般都是临时去百度用的信息，这样很繁琐所以决定造轮子撸了个随机身份生成的。\n\n## 介绍\n\n该脚本生成信息：中国黑客ID\\姓名\\年龄\\性别\\身份证\\手机号\\组织机构代码\\统一社会信用代码\n\n## 脚本编写原理\n\n**脚本的函数：** genMobile()、genIdCard()、genName()、genOrgCode()、genCreditCode()\n\ngenMobile() 为随机生成手机号的函数 \n\ngenName() 为随机生成姓名的函数\n\ngenIdCard() 为随机生成身份证的函数\n\ngenOrgCode() 为随机生成组织机构代码的函数\n\ngenCreditCode() 为随机生成统一社会信用代码的函数\n\n### genMobile()\n\n随机生成手机号：需要知道国内手机号的构成\n\n1.长度为十一位\n\n2.前三位表示运营商\n\n现在我们只需要做到收集手机号号段的前三位以及对应的运营商：\n\n```python\nprelist = {\"133\":\"电信\",\"149\":\"电信\",\"153\":\"电信\",\"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\":\"移动\"}\n```\n\n获取该数组的长度：len(prelist) -\u003e 42\n\n随机生成下标获取三位数：`prelist.keys()[random.randint(0,41)]`\n\n然后再随机填补后8位即可：\n\n```python\ndef genMobile():\n    prelist = {\"133\":\"电信\",\"149\":\"电信\",\"153\":\"电信\",\"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\":\"移动\"}\n    three = list(prelist.keys())[random.randint(0,len(prelist)-1)]\n    mobile = three + \"\".join(random.choice(\"0123456789\") for i in range(8))\n    op = prelist[three]\n    return {mobile:op}\n```\n\n### genName()\n\n随机生成姓名：中文名字通常为2、3位汉字组成\n\n1.收集常用的姓氏随机取其一个：\n\n```python\ndef first_name():\n    first_name_list = ['赵', '钱', '孙', '李', '周', '吴', '郑', '王', '冯', '陈', '褚', '卫', '蒋', '沈', '韩', '杨', '朱', '秦', '尤', '许',\n                '何', '吕', '施', '张', '孔', '曹', '严', '华', '金', '魏', '陶', '姜', '戚', '谢', '邹', '喻', '柏', '水', '窦', '章',\n                '云', '苏', '潘', '葛', '奚', '范', '彭', '郎', '鲁', '韦', '昌', '马', '苗', '凤', '花', '方', '俞', '任', '袁', '柳',\n                '酆', '鲍', '史', '唐', '费', '廉', '岑', '薛', '雷', '贺', '倪', '汤', '滕', '殷', '罗', '毕', '郝', '邬', '安', '常',\n                '乐', '于', '时', '傅', '皮', '卞', '齐', '康', '伍', '余', '元', '卜', '顾', '孟', '平', '黄', '和', '穆', '萧', '尹',\n                '姚', '邵', '堪', '汪', '祁', '毛', '禹', '狄', '米', '贝', '明', '臧', '计', '伏', '成', '戴', '谈', '宋', '茅', '庞',\n                '熊', '纪', '舒', '屈', '项', '祝', '董', '梁']\n    n = random.randint(0, len(first_name_list) - 1)\n    f_name = first_name_list[n]\n    return f_name\n```\n\n2.这里一开始想搜罗常用的名字，但参考了其他师傅的代码发现随机生成中文字符更好一点：\n\n```python\ndef GBK2312():\n    head = random.randint(0xb0, 0xf7)\n    body = random.randint(0xa1, 0xf9)\n    val = f'{head:x}{body:x}'\n    st = bytes.fromhex(val).decode('gb2312')\n    return st\n```\n\n3.随机生成名字的第二个字：(这里用一个list做一个空值，随机取生成的汉字或空值，**用于成为随机生成2位名字或3位名字**)\n\n```python\ndef second_name():\n    second_name_list = [GBK2312(), '']\n    n = random.randint(0, 1)\n    s_name = second_name_list[n]\n    return s_name\n```\n\n4.随机生成名字的最后一个字：(用于满足三个汉字的名字)\n\n```python\ndef last_name():\n    return GBK2312()\n```\n\n5.拼接\n\n```python\ndef last_name():\n    return GBK2312()\n```\n\n### genIdCard()\n\n随机生成身份证：公民身份号码是由17位数字码和1位校验码组成\n\n18位数字组合的方式是：\n\n| 1 1 0 1 0\t2 | Y Y\tY Y\tM M D D | 8 8         | 8           | X           |\n| -------------- | --------------------- | ----------- | ----------- | ----------- |\n| 区域码(6位)    | 出生日期码(8位)       | 顺序码(2位) | 性别码(1位) | 校验码(1位) |\n\n- 6位区域码爬取http://www.360doc.com/content/12/1010/21/156610_240728293.shtml，存到了`districtcode.py`\n\n\u003e **区域码** 指的是公民常住户口所在县（市、镇、区）的[行政区划代码](https://zh.wikipedia.org/wiki/%E4%B8%AD%E5%8D%8E%E4%BA%BA%E6%B0%91%E5%85%B1%E5%92%8C%E5%9B%BD%E8%A1%8C%E6%94%BF%E5%8C%BA%E5%88%92%E4%BB%A3%E7%A0%81)，如110102是北京市-西城区。但港澳台地区居民的身份号码只精确到省级。\n\n- 8位出生日期码，具体Python代码如下：\n\n```python\nage = random.randint(16,60) #可调整生成的年龄范围（身份证），这边是16-60岁\ny = date.today().year - age #生成的年份\nm = date(y, 1, 1) #生成的月份，初始值为1月1日\nd = timedelta(days=random.randint(0, 364)) #随机生成的天数\ndatestring = str(m + d) #加天数得到最终值\n```\n\n\u003e **出生日期码** 表示公民出生的公历年（4位）、月（2位）、日（2位）。\n\n- 2位顺序码\n\n\u003e **顺序码** 表示在同一区域码所标识的区域范围内，对同年、同月、同日出生的人编定的顺序号。\n\n- 1位性别码\n\n\u003e **性别码** 奇数表示男性，偶数表示女性。\n\n- 最后一位是**校验码**，这里采用的是**ISO 7064:1983,MOD 11-2**校验码系统。校验码为一位数，但如果最后采用校验码系统计算的校验码是“10”，碍于身份证号码为18位的规定，则以“X”代替校验码“10”。\n\n最难的还是校验码的算法，参考师傅的解说：\n\n\u003e1.将前面的身份证号码17位数分别乘以不同的系数。从第一位到第十七位的系数分别为：7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2 \n\n\u003e2.将这17位数字和系数相乘的结果相加。 \n\n\u003e3.用加出来和除以11，得余数\n\n\u003e4.余数只可能是0 1 2 3 4 5 6 7 8 9 10这11个数字，其分别对应的最后一位身份证的号码为1 0 X 9 8 7 6 5 4 3 2。 \n\n\u003e5.通过上面得知如果余数是2，就会在身份证的第18位数字上出现罗马数字的Ⅹ，如果余数是10，身份证的最后一位号码就是2。 \n\n测试代码如下，取了几个真实的身份证号码发现可用：\n\n```python\ndef test(id_num):\n\tid_code_list = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]\n\tcheck_code_list = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2]\n\ta = 0\n\tprint(len(id_num))\n\tfor i in range(17):\n\t\ta = a + (int(id_num[i]) * id_code_list[int(i)])\n\tprint(check_code_list[a % 11])\n```\n\n整合一下（Copy）就变成了如下完整的代码：\n\n```python\ndef genIdCard(age,gender):\n    area_code = ('%s' % random.choice(list(area_dict.keys())))\n    id_code_list = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]\n    check_code_list = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2]\n    if str(area_code) not in area_dict.keys():\n        return None\n    datestring = str(date(date.today().year - age, 1, 1) + timedelta(days=random.randint(0, 364))).replace(\"-\", \"\")\n    rd = random.randint(0, 999)\n    if gender == 0:\n        gender_num = rd if rd % 2 == 0 else rd + 1\n    else:\n        gender_num = rd if rd % 2 == 1 else rd - 1\n    result = str(area_code) + datestring + str(gender_num).zfill(3)\n    b = result + str(check_code_list[sum([a * b for a, b in zip(id_code_list, [int(a) for a in result])]) % 11])\n    return b\n```\n\n## 参考\n\nhttps://www.cnblogs.com/evening/archive/2012/04/19/2457440.html\n\nhttps://www.cnblogs.com/thunderLL/p/7682148.html\n\nhttps://blog.csdn.net/ak739105231/article/details/83932151\n\nhttps://github.com/jayknoxqu/id-number-util\n\nhttps://blog.csdn.net/tobacco5648/article/details/50613025\n\nhttps://github.com/xbeginagain/generator","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgh0stkey%2FRGPerson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgh0stkey%2FRGPerson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgh0stkey%2FRGPerson/lists"}