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.
[ Last edited by namejm on 2007-3-6 at 10:01 PM ]
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
| Rater | Score | Time |
|---|---|---|
| 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
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
考虑问题复杂化,解决问题简洁化。


