可以使用手机号码前三位来判断运营商,一般情况下:
- 中国移动号码前三位:134-139、147、150-152、157-159、178、182-184、187-189
- 中国联通号码前三位:130-132、145、155-156、166、175-176、185-186
- 中国电信号码前三位:133、149、153、173-174、177、180-181、189、199
以下是一个使用 Python 实现的判断手机号码运营商的程序示例:
```python
def judge_operator(phone_number):
if len(phone_number) != 11:
return "请输入11位手机号码"
elif not phone_number.isdigit():
return "手机号码只能为数字"
else:
operators = {"移动": ["134", "135", "136", "137", "138", "139", "147", "150", "151", "152", "157", "158", "159", "178", "182", "183", "184", "187", "188", "198"],
"联通": ["130", "131", "132", "145", "155", "156", "166", "175", "176", "185", "186"],
"电信": ["133", "149", "153", "173", "174", "177", "180", "181", "189", "199"]}
prefix = phone_number[:3]
for operator in operators:
if prefix in operators[operator]:
return operator
return "未知运营商"
```
你可以调用该函数,并传入一个手机号码作为参数,即可得到该手机号码所属的运营商。
联通:2G号段(GSM):130、131、132、155、156;3G号段(WCDMA,沃-WO):185、186.
电信:2G号段(CDMA):133、153;3G号段(CDMA2000,天翼):180、189.
不联网运行不可能知道 难道还要运营商每天帮你更新数据不成
比如使用Webservcie就比较省事。
Endpoint: http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx
Disco: http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?disco
WSDL: http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl
国内手机号码归属地查询WEB服务,提供最新的国内手机号码段归属地数据,每月更新。包括最新的电信天翼189号段和最新移动152号段、TD-SCDMA188号段。数据更全更准确,是目前国内最新最全的手机号码段数据库! http://www.webxml.com.cn/zh_cn/web_services.aspx