IMSI与MSISDN对应规则

正好项目中有用到imsi与msisdn对应规则,在此记录一下。

简介

  • IMSI(International Mobile Subscriber Identity):
    IMSI=MCC(移动国家码)+MNC(移动网号)+MSIN( PLMN中唯一识别MS)
  • MSISDN(Mobile Subscriber International ISDN/PSTN number):
    MSISDN=CC(国家码)+NDC(国内接入号)+SN(用户号码)

    IMSI

    IMSI是区别移动用户的标志,储存在SIM卡中,可用于区别移动用户的有效信息。其总长度不超过15位,同样使用0~9的数字。

    MCC

    MCC是移动用户所属国家代号,占3位数字,中国的MCC规定为460。

    MNC

    MNC为移动网络码,共2-3位,中国国内当前如为下表所示:
运营商 MNC号码
移动 00, 02, 07
联通 01, 06
电信 03, 05
电信4G 11
铁通 20

MSIN

MSIN为移动用户识别号码,10-11位,其结构如下:
$$CC+M0M1M2M3+ABCD$$
CC由不同运营商分配,其中的M0M1M2M3和MDN号码中的H0H1H2H3可存在对应关系,ABCD四位为自由分配。

MSISDN

其实MSISDN就是我们平时所说的手机号码。
$$MSISDN=CC+NDC+SN$$

其中:
CC=国家码 (中国为86)
NDC=国内目的码
SN=用户号码

NDC为:
每个GSM的网络均分配一个国内目的码(NDC)。也可以要求分配两个以上的NDC号。MSISDN的号长是可变的(取决于网络结构与编号计划),不包括字冠,最长可以达到15位,我国GSM的国内身份号码为11位。
$$NDC=N1N2N3(接入号)+H1H2H3H4(HLR的识别号)$$
接入号用于识别网络,我们目前采用:139、138……。
HLR识别号表示用户归属的HLR,也表示移动业务本地网号。

例如:133-3333

IMSI与MSISDN对应关系

切记IMSI与MSISDN不一定完全有对应关系,但是有一些可以作为借鉴。
当前收集了移动和联通的对应关系,其他暂时无法获取,且无法推导。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
val s130 = """^46001(\d{3})(\d)[0,1]\d+""".r
val s131 = """^46001(\d{3})(\d)9\d+""".r
val s132 = """^46001(\d{3})(\d)2\d+""".r
val s134 = """^460020(\d)(\d{3})\d+""".r
val s13x0 = """^46000(\d{3})([5,6,7,8,9])\d+""".r
val s13x = """^46000(\d{3})([0,1,2,3,4])(\d)\d+""".r
val s150 = """^460023(\d)(\d{3})\d+""".r
val s151 = """^460021(\d)(\d{3})\d+""".r
val s152 = """^460022(\d)(\d{3})\d+""".r
val s155 = """^46001(\d{3})(\d)4\d+""".r
val s156 = """^46001(\d{3})(\d)3\d+""".r
val s157 = """^460077(\d)(\d{3})\d+""".r
val s158 = """^460028(\d)(\d{3})\d+""".r
val s159 = """^460029(\d)(\d{3})\d+""".r
val s147 = """^460079(\d)(\d{3})\d+""".r
val s185 = """^46001(\d{3})(\d)5\d+""".r
val s186 = """^46001(\d{3})(\d)6\d+""".r
val s187 = """^460027(\d)(\d{3})\d+""".r
val s188 = """^460078(\d)(\d{3})\d+""".r
val s1705 = """^460070(\d)(\d{3})\d+""".r
val s170x = """^46001(\d{3})(\d)8\d+""".r
val s178 = """^460075(\d)(\d{3})\d+""".r
val s145 = """^46001(\d{3})(\d)7\d+""".r
val s182 = """^460026(\d)(\d{3})\d+""".r
val s183 = """^460025(\d)(\d{3})\d+""".r
val s184 = """^460024(\d)(\d{3})\d+""".r

val calphone = imsi match {
case s130(bcd,a) => "130"+a+bcd
case s131(bcd,a) => "131"+a+bcd
case s132(bcd,a) => "132"+a+bcd
case s134(a,bcd) => "134"+a+bcd
case s13x0(bcd,s) => "13"+s+"0"+bcd
case s13x(bcd,s,a) => "13"+(s.toInt+5)+a+bcd
case s150(a,bcd) => "150"+a+bcd
case s151(a,bcd) => "151"+a+bcd
case s152(a,bcd) => "152"+a+bcd
case s155(bcd,a) => "155"+a+bcd
case s156(bcd,a) => "156"+a+bcd
case s157(a,bcd) => "157"+a+bcd
case s158(a,bcd) => "158"+a+bcd
case s159(a,bcd) => "159"+a+bcd
case s147(a,bcd) => "147"+a+bcd
case s185(bcd,a) => "185"+a+bcd
case s186(bcd,a) => "186"+a+bcd
case s187(a,bcd) => "187"+a+bcd
case s188(a,bcd) => "188"+a+bcd
case s1705(a,bcd) => "170"+a+bcd
case s170x(bcd,a) => "170"+a+bcd
case s178(a,bcd) => "178"+a+bcd
case s145(bcd,a) => "145"+a+bcd
case s182(a,bcd) => "182"+a+bcd
case s183(a,bcd) => "183"+a+bcd
case s184(a,bcd) => "184"+a+bcd
case _ => "0"
}

再次提醒,当前两者之间关系并非一定如此,仅作参考。

热评文章