Board logo

标题: [原创][分享]手机归属地查询批处理版 [打印本页]

作者: singlion     时间: 2008-12-6 22:03    标题: [原创][分享]手机归属地查询批处理版

有幸得到了手机归属地数据库,有15万3千多条记录,包含最新的151、155、157号码段的归属地数据,2008年9月11日整理完成,于是将它转换成文本文档,用批处理来查询。


附件中总共又三个文件,主文件代码如下
@echo off
title 手机归属地查询 Write by 李国灿  singlion@126.com
color 79
setlocal enabledelayedexpansion
   echo                      ╭──────────╮
   echo        ╭──────┤   手机归属地查询   ├────────╮
   echo        │            ╰──────────╯                │
   echo        │   本程序所带数据库为2008年9月11日整理完成,        │   
   echo        │包含151、155和157号码段。                           │
   echo        │                                                    │
   echo        │使用方法:                                          │
   echo        │    输入手机号码(至少输入前七位),按回车键即可。  │
   echo        │                                                    │
   echo        │注意事项:                                          │
   echo        │                                                    │
   echo        │    1.请勿修改本程序,任何微小的修改都可能导致      │
   echo        │本程序无法正常运行。                                │
   echo        │                                                    │
   echo        │    2.所有数据都存放在文件“List.txt”中,请勿删    │
   echo        │ 除,也不要把它改名,否则将无法使用本程序。         │
   echo        │                                                    │
   echo        │    3.若以后不小心修改了本程序而导致无法正常使      │
   echo        │ 用,你可以自行打开文件“List.txt”用肉眼搜索^^_^^    │
   echo        │                                                    │
   echo        ╰──────────────────────────╯
   echo. & echo        请按任意键继续... & pause>nul

:lookup
cls
echo. & echo. & echo. & echo. & echo. & echo. & echo. & echo. & echo.
set /p mystr=        [请输入手机号]:
if not defined mystr goto :lookup
set count=0
:intercept
set /a count+=1
for /f %%i in ("%count%") do if not "!mystr:~%%i,1!"=="" goto intercept
if %count% lss 7 (
   echo         无效手机号(最少需要手机号的前7位)。
   echo         请按任意键继续...
   pause >nul
   goto :lookup
)
if %count% GEQ 37 (
   echo         无效手机号(不能长于11位)。
   echo         请按任意键继续...
   pause>nul
   goto :lookup
)
cls & echo 正在查询,请稍候...
for /f "tokens=3,4 delims=:." %%i in ("%time%") do (
    set /a sb=%%i
    set /a msb=%%j
)
set where=
set card=
set number=%mystr:~0,7%
for /f "eol=; tokens=2,3,4 delims=," %%i in (list.txt) do (
   if %%i==%number% (
      set where=%%j
      set card=%%k
      goto :result
   )
)
for /f "tokens=3,4 delims=:." %%i in ("%time%") do (
    set /a se=%%i
    set /a mse=%%j
)
if "%mse%" lss "%msb%" (
    set /a mse=%mse%+100
    set /a se=%se%-1
)
if "%se%" lss "%sb%" (
    set /a se=%se%+60
)
set /a s=%se%-%sb%
set /a ms=%mse%-%msb%
cls & echo. & echo  耗时%s%.%ms%秒。没有找到结果。请按任意键继续...
pause>nul
goto :ss
:result
cls
call table.bat %mystr% %where% %card%
echo.
for /f "tokens=3,4 delims=:." %%i in ("%time%") do (
    set /a se=%%i
    set /a mse=%%j
)
if "%mse%" lss "%msb%" (
    set /a mse=%mse%+100
    set /a se=%se%-1
)
if "%se%" lss "%sb%" (
    set /a se=%se%+60
)
set /a s=%se%-%sb%
set /a ms=%mse%-%msb%
echo         查询耗时%s%.%ms%秒。请按任意键继续...
pause>nul
:ss
cls
echo                  ╭────────╮
echo        ╭────┤ 是否继续查询? ├─────╮
echo        │        ╰────────╯          │
echo        │ 输入数字并按回车键:                 │
echo        │                                      │
echo        │    1.继续查询;                      │
echo        │                                      │
echo        │    2.退出程序。                      │
echo        │                                      │
echo        ╰───────────────────╯
set /p select=        
if "%select%"=="1" goto :lookup
goto :eof
pause
文件table.bat代码如下(最好不要更改文件名):
@echo off
if {%1}=={} goto :eof
setlocal enabledelayedexpansion
set blank=
set m=%1
set n=%2
set o=%3
set c=0
:intercept
set /a c+=1
for /f %%i in ("%c%") do if not "!m:~%%i,1!"=="" goto intercept

set d=0
:intercep
set /a d+=1
for /f %%j in ("%d%") do if not "!n:~%%j,1!"=="" goto intercep

set e=0
:interce
set /a e+=1
for /f %%k in ("%e%") do if not "!o:~%%k,1!"=="" goto interce

set /a c=38-%c%
for /l %%x in (1,1,%c%) do set m=!m!%blank%

set /a d=26-%d%*2
for /l %%y in (1,1,%d%) do set n=!n!%blank%

set /a e=26-%e%*2
for /l %%y in (1,1,%e%) do set o=!o!%blank%

echo                      ╭────╮
echo        ╭──────┤查询结果├───────╮
echo        │            ╰────╯              │
echo        │%m%│
echo        ├─────┬─────────────┤
echo        │ 归属地   │%n%│
echo        ├─────┼─────────────┤
echo        │ 卡类型   │%o%│
echo        ╰─────┴─────────────╯
最后是txt格式的数据库,在附件里面。
http://upload.cn-dos.net/img/1168.rar

另,Access数据库
http://upload.cn-dos.net/img/1169.rar

[ Last edited by singlion on 2008-12-6 at 22:07 ]
作者: zh159     时间: 2008-12-7 03:13
错误:

  Quote:
for /f "eol=; tokens=2,3,4 delims=," %%i in (list.txt) do (
   if %%i==%number% (
      set where=%%j
      set card=%%k
      goto :result
   )
)

数据库名称不对,分隔位置号不对
上面这句效率低,改为:

  Quote:
for /f "eol=; tokens=1,2,3 delims=," %%i in ('findstr "%number%" list.txt') do (
      set where=%%j
      set card=%%k
      goto :result
)


作者: HAT     时间: 2008-12-7 11:52
手机号码归属地查询批处理单机版
http://www.cn-dos.net/forum/viewthread.php?tid=31250

IP地址地理位置/手机号码归属地查询(网络版)
http://www.cn-dos.net/forum/viewthread.php?tid=31240
作者: singlion     时间: 2008-12-7 17:08
晕,原来早就有了啊,惭愧...