phonedata

package module
v0.0.0-...-ce93786 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2024 License: GPL-3.0 Imports: 7 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

手机号码归属地信息库、手机号归属地查询

这可能是github上能找到的最新最全的中国境内手机号归属地信息库

基于GO语言实现,使用二分查找法。

  • 归属地信息库文件大小:4,098,913 字节
  • 归属地信息库最后更新:2021年08月
  • 手机号段记录条数:454336

phone.dat文件格式

    | 4 bytes |                     <- phone.dat 版本号(如:1701即17年1月份)
    ------------
    | 4 bytes |                     <-  第一个索引的偏移
    -----------------------
    |  offset - 8            |      <-  记录区
    -----------------------
    |  index                 |      <-  索引区
    -----------------------
  1. 头部为8个字节,版本号为4个字节,第一个索引的偏移为4个字节;
  2. 记录区 中每条记录的格式为"<省份>|<城市>|<邮编>|<长途区号>\0"。 每条记录以'\0'结束;
  3. 索引区 中每条记录的格式为"<手机号前七位><记录区的偏移><卡类型>",每个索引的长度为9个字节;

安装使用

vi test.go

package main

import (
	"fmt"

	"github.com/xluohome/phonedata"
)

func main() {
	pr, err := phonedata.Find("18957509123")
	if err != nil {
		panic(err)
	}
	fmt.Print(pr)
}

go run test.go

PhoneNum: 18957509123
AreaZone: 0575
CardType: 中国电信
City: 绍兴
ZipCode: 312000
Province: 浙江

快速使用

cmd 目录下phonedata是一个命令行查询手机号归属地信息的终端程序。


Linux:
#PHONE_DATA_DIR=../ ./phonedata  18957509123

Windows:
>set PHONE_DATA_DIR=../
>phonedata.exe  18957509123

stdout:

PhoneNum: 18957509123
AreaZone: 0575
CardType: 中国电信
City: 绍兴
ZipCode: 312000
Province: 浙江

性能测试

Thinkpad s3 (Intel(R) Core(TM) i5-4200U CPU @ 1.60GHz)

go version go1.13.4 windows/amd64

go test -v --bench="."

BenchmarkFindPhone-4     1964847               607 ns/op

我仅想要phone.dat的csv文本文件?

好。下载地址 https://git.oschina.net/oss/phonedata/attach_files

其他语言实现

python: https://github.com/lovedboy/phone

php: https://github.com/shitoudev/phone-location , https://github.com/iwantofun/php_phone

php ext: https://github.com/jonnywang/phone

java: https://github.com/fengjiajie/phone-number-geo , https://github.com/EeeMt/phone-number-geo

Node: https://github.com/conzi/phone

C++: https://github.com/yanxijian/phonedata

C#: https://github.com/sndnvaps/Phonedata

Rust: https://github.com/vincascm/phonedata

Kotlin: https://github.com/bytebeats/phone-geo

安全保证

手机号归属地信息是通过网上公开数据进行收集整理。

对手机号归属地信息数据的绝对正确,我不做任何保证。因此在生产环境使用前请您自行校对测试。

客户案例

感谢

@lovedboy https://github.com/lovedboy

@zhengji https://github.com/zheng-ji/gophone

联系作者

加作者微信

wx.jpg

Documentation

Index

Constants

View Source
const (
	CMCC               byte = iota + 0x01 //中国移动
	CUCC                                  //中国联通
	CTCC                                  //中国电信
	CTCC_v                                //电信虚拟运营商
	CUCC_v                                //联通虚拟运营商
	CMCC_v                                //移动虚拟运营商
	CBCC                                  //中国广电
	CBCC_v                                //广电虚拟运营商
	INT_LEN            = 4
	CHAR_LEN           = 1
	HEAD_LENGTH        = 8
	PHONE_INDEX_LENGTH = 9
	PHONE_DAT          = "phone.dat"
)

Variables

View Source
var (
	CardTypemap = map[byte]string{
		CMCC:   "中国移动",
		CUCC:   "中国联通",
		CTCC:   "中国电信",
		CBCC:   "中国广电",
		CTCC_v: "中国电信虚拟运营商",
		CUCC_v: "中国联通虚拟运营商",
		CMCC_v: "中国移动虚拟运营商",
		CBCC_v: "中国广电虚拟运营商",
	}
)

Functions

func Debug

func Debug()

Types

type PhoneRecord

type PhoneRecord struct {
	PhoneNum string
	Province string
	City     string
	ZipCode  string
	AreaZone string
	CardType string
}

func Find

func Find(phone_num string) (pr *PhoneRecord, err error)

二分法查询phone数据

func (PhoneRecord) String

func (pr PhoneRecord) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址