China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-20 19:44
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original] ID Number Information Query Tool [Updated on 07-3-6] View 4,271 Replies 14
Original Poster Posted 2007-03-05 06:47 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Usage method: Please save the date.txt in the attachment in the same directory as this code for use.

Precautions: This database originates from the latest data of the National Bureau of Statistics of the People's Republic of China on December 31, 2006. Before this, if the original administrative division code is canceled or changed due to changes in the administrative division, some legal IDs will be considered illegal.

@echo off
:: Function:
:: 1. Query gender, date of birth and place of household registration according to the number
:: 2. Upgrade 15-digit number to 18-digit
:: 3. Batch generate ID card numbers according to place of household registration and date of birth
::
:: Known bugs:
:: 1. Input detection is not strict
:: 2. The speed of generating ID is slow
::
:: Code by JM 2007-3-4 CMD@XP
::
:: Update history:
::
:: 07.3.6
::   Corrected the error that it always shows an illegal number when upgrading a 15-digit number to an 18-digit number;

mode con lines=20 cols=50
title ID Card Number Information Query Tool
setlocal enabledelayedexpansion

set check_num=10X98765432

:Main
cls
set flag=
set IDflag=
echo.&echo.&echo.&echo.
echo 1. Query basic information through 18-digit number
echo.
echo 2. Upgrade 15-digit number to 18-digit
echo.
echo 3. Generate ID card number of specified area
echo.&echo.&echo.
echo __________________________________________________
echo.
set choice=
set /p choice= Please enter the function code (press Enter directly to exit):

if "%choice%"=="1" goto Get_Info
if "%choice%"=="2" goto UpDate
if "%choice%"=="3" goto Creat_ID
if defined choice goto Main
exit

:Get_Info
cls
echo.&echo.&echo.&echo.&echo.
set ID=
set /p ID= Please enter 18-digit ID card number:
call :Check_ID %ID%
if defined flag (
call :PickUp_Info
) else call :ERR
echo Press any key to return to the main interface...
pause>nul
goto Main

:UpDate
cls
echo.&echo.&echo.&echo.&echo.
set IDflag=15
set ID=
set /p ID= Please enter 15-digit ID card number:
set ID_15=%ID%
set ID=%ID:~0,6%19%ID:~6%
call :Check_ID %ID%
if defined flag (
call :PickUp_Info
) else call :ERR
echo Press any key to return to the main interface...
pause>nul
goto Main

:Creat_ID
cls
echo.&echo.
echo   Place names can only be retrieved to county-level and above administrative divisions; must
echo.
echo Input in the order of administrative levels, can jump levels, and multiple keywords are separated by spaces. For example: Sichuan Chengdu Qingyang District or
echo.
echo Sichuan Qingyang District or Chengdu.
echo.
echo    Birthday must be in the format of 6 digits, for example: 20070130.
echo.
echo __________________________________________________
echo.
set place=
set birthday=
set exp=
set /p place= Please enter area keywords:
echo.
set /p birthday= Please enter 8-digit format date of birth:
if "%birthday:~7,1%"=="" (call :ERR & pause & goto Main)
if not "%birthday:~0,8%"=="%birthday%" (call :ERR & pause & goto Main)
set /a day=1%birthday% 2>nul||(call :ERR & pause & goto Main)
if not "%day:~1%"=="%birthday%" (call :ERR & pause & goto Main)

cls
echo.&echo.
echo There are ^(can press Ctrl^+C to pause execution halfway^) conforming numbers:
echo.
for %%i in (%place%) do set exp=!exp!.*%%i
for /f "tokens=1*" %%i in ('findstr "%exp:~2%" date.txt') do (
set ID_place=%%i
set ID_tmp=!ID_place:~0,1!
for /l %%j in (1,1,9) do (
if !ID_tmp! equ %%j call :IDs
)
)
if not defined flag (
echo.&echo.&echo.
echo The place name with the keyword %place% is not found in the database!
echo.&echo.&echo.
)
echo Press any key to return to the main interface...
pause>nul
goto Main

rem ==== Check if the number is legal ====
:Check_ID
set ID=%1
set ID_tmp=%1
if defined IDflag (
if "%ID:~16,1%"=="" set flag=&goto :eof
if not "%ID:~0,17%"=="%1" set flag=&goto :eof
) else (
if "%ID:~17,1%"=="" set flag=&goto :eof
if not "%ID:~0,18%"=="%1" set flag=&goto :eof
if /i "%ID:~-1%"=="x" set ID_tmp=%ID:~0,-1%
)
set /a ID_tmp_1=1!ID_tmp:~0,6! 2>nul||(set flag=&goto :eof)
set /a ID_tmp_2=1!ID_tmp:~6,8! 2>nul||(set flag=&goto :eof)
set /a ID_tmp_3=1!ID_tmp:~14! 2>nul||(set flag=&goto :eof)
if not "!ID_tmp_1:~1!!ID_tmp_2:~1!!ID_tmp_3:~1!"=="!ID_tmp!" set flag=&goto :eof
set sum=0
set str_wi=7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2 1
for /l %%i in (0,1,16) do (
set ai=!ID:~%%i,1!
call :Get_Num %%i !str_wi!
set /a product=!ai!*!wi! 2>nul
set /a sum+=!product!
)
set /a mod=%sum%%%11
set last_num=!check_num:~%mod%,1!
if defined IDflag (
set ID=%ID%%last_num%
set flag=1
goto :eof
)
if /i "%ID:~-1%"=="%last_num%" (
set flag=1
) else set flag=
goto :eof

:Get_Num
:: Extract the value at the corresponding position in %str_wi%
for /l %%i in (1,1,%1) do shift
set wi=%2
goto :eof

:PickUp_Info
set char=%ID:~-2,1%
set /a mod=%char%%%2
if %mod% equ 0 (
set SEX=Female
) else set SEX=Male
for /f "tokens=1*" %%i in ('findstr "%ID:~0,6%" date.txt') do (
set flag=exist
cls
echo.&echo.&echo.&echo.
if defined IDflag (
echo ID card number: %ID_15%
echo.
echo Upgraded number: %ID%
) else echo ID card number: %ID%
echo.
echo Gender: %SEX%
echo.
echo Date of birth: %ID:~6,4% year %ID:~10,2% month %ID:~12,2% day
echo.
echo Place of household registration: %%j
echo.&echo.&echo.&echo.
)
if not "%flag%"=="exist" call :ERR
goto :eof

rem ==== Generate legal number ====
:IDs
for /l %%i in (0,1,999) do (
for %%j in (0 1 2 3 4 5 6 7 8 9 X) do (
set ID=00%%i%%j
call :Check_ID %ID_place%%birthday%!ID:~-4!
if defined flag echo %ID_place%%birthday%!ID:~-4!
)
)
goto :eof

rem ==== Error prompt ====
:ERR
echo.&echo.
echo Illegal number
echo.&echo.&echo.
goto :eof


[ Last edited by namejm on 2007-3-6 at 10:01 PM ]
Recent Ratings for This Post ( 4 in total) Click for details
RaterScoreTime
huzixuan +2 2007-03-05 06:56
jmz573515 +8 2007-03-05 07:29
lotus516 +4 2007-03-09 11:16
xycoordinate +2 2007-03-09 23:11
Attachments
数据库及背景知识.rar (26.43 KiB, Downloads: 298)
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 2 Posted 2007-03-05 07:03 ·  中国 安徽 芜湖 电信
高级用户
★★
Credits 537
Posts 219
Joined 2006-10-31 21:08
19-year member
UID 69036
Gender Male
From 芜湖
Status Offline
Please have comrades who want to forge false certificates correct their thoughts!
江湖远
碧空长
路茫茫

一个人漫无目的的奔跑,风,刺骨的冷....
Floor 3 Posted 2007-03-05 07:30 ·  中国 辽宁 本溪 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
That's really a nice thing.
Floor 4 Posted 2007-03-05 07:46 ·  中国 甘肃 兰州 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
It would be nice to be able to find the detailed address.
Floor 5 Posted 2007-03-05 08:46 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Originally posted by vkill at 2007-3-4 18:46:
It would be great if we could find the detailed address.

It would be even better to find the other party's detailed information, three-digit data, and photos.


PS: The database doesn't have my old version of the area code: 4525
Floor 6 Posted 2007-03-05 09:22 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Every time I have to re-search...

The first time, I stored them (the first 6 digits) into a variable... Isn't the speed improved?
Floor 7 Posted 2007-03-05 10:39 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Originally posted by slore at 2007-3-4 20:22:
Every time you have to re-index...

When you do it for the first time, store them (the first 6 digits) into a variable... Wouldn't that improve the speed?

The more variables in a batch script, the slower the execution efficiency.
If you store them into variables, with about 4000, the loading time is also considerable.
I tried with 7000, and after loading, the speed slowed down a lot; using findstr to search is very fast. I made 7000 data into a file, and findstr can almost search immediately.
Floor 8 Posted 2007-03-05 10:40 ·  中国 江苏 无锡 电信
初级用户
Credits 57
Posts 23
Joined 2006-10-29 08:23
19-year member
UID 68753
Gender Male
Status Offline
The楼主's P processing really reaches the realm of being extremely excellent!
Floor 9 Posted 2007-03-08 23:26 ·  中国 湖北 武汉 武昌区 电信
初级用户
Credits 20
Posts 9
Joined 2007-03-08 22:23
19-year member
UID 81104
Gender Male
Status Offline
Because the coding of ID cards has patterns, this batch processing uses this pattern to check, generate, or convert. It is impossible to provide detailed information. It is also not allowed by law.
Floor 10 Posted 2007-03-09 01:53 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Originally posted by zh159 at 2007-3-4 21:39:

The more variables in a batch script, the slower the execution efficiency.
If stored in variables, with about 4000, the loading time is also considerable.
I tried 7000 ones, and the speed slowed down a lot after loading; findstr searches very quickly. I made 7000 data into a file, and findstr can almost search immediately.


Then directly, in a data folder, there are.txt files with the first 6 digits. The text content corresponds to the address^

Then directly, how is the speed of type this?
Floor 11 Posted 2007-03-09 09:21 ·  中国 广东 中山 电信
初级用户
Credits 128
Posts 16
Joined 2007-01-26 04:00
19-year member
UID 77697
Gender Male
Status Offline
namejm moderator is amazing!! I'll give it a try!
Floor 12 Posted 2007-03-09 11:16 ·  中国 江西 赣州 电信
高级用户
★★
论坛上抢劫的
Credits 551
Posts 246
Joined 2006-09-21 12:35
19-year member
UID 63270
Status Offline
Haha, interesting!
Floor 13 Posted 2007-03-09 11:28 ·  中国 广东 东莞 电信
初级用户
Credits 107
Posts 48
Joined 2006-11-30 12:06
19-year member
UID 72174
Gender Male
Status Offline
The landlord is amazing, I'm convinced!
Playing P to this level!
Floor 14 Posted 2007-03-09 23:11 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 493
Posts 228
Joined 2007-02-16 00:38
19-year member
UID 79596
Gender Male
From 安徽
Status Offline
Floor 15 Posted 2009-06-21 06:06 ·  中国 广东 阳江 电信
新手上路
Credits 16
Posts 14
Joined 2006-06-23 05:58
20-year member
UID 57436
Status Offline
Forum Jump: