查找手机号码的电话公司?
我有一个应用程序,人们可以在其中提供电话号码,它会通过电子邮件短信网关向该电话号码发送短信。但是,为了使其正常工作,我需要给定号码的电话公司,以便我将电子邮件发送到正确的短信网关。我见过一些允许您查找此信息的服务,但它们都不是 Web 服务或数据库的形式。
例如,http://tnid.us就提供了这样的服务。我的电话号码的输出示例:
他们从哪里获取每个号码的“当前电话公司”信息。这是免费提供的信息吗?是否有数据库或某种网络服务可以用来获取给定手机号码的信息?
I have an application where people can give a phone number and it will send SMS texts to the phone number through EMail-SMS gateways. For this to work however, I need the phone company of the given number so that I send the email to the proper SMS gateway. I've seen some services that allow you to look up this information, but none of them in the form of a web service or database.
For instance, http://tnid.us provides such a service. Example output from my phone number:
Where do they get the "Current Telephone Company" information for each number. Is this freely available information? Is there a database or some sort of web service I can use to get that information for a given cell phone number?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要的是 HLR(家庭位置寄存器)号码查找。
在其基本形式中,此类 API 将需要国际格式的电话号码(例如 +15121234567),并将返回其 IMSI,其中包括其 MCC (为您提供国家/地区)和 MNC(为您提供手机的运营商)。甚至可能包括手机当前的运营商(例如,判断手机是否正在漫游)。如果手机当前超出范围或已关闭,则该功能可能无法工作。在这些情况下,根据 API 提供商的不同,他们可能会为您提供缓存的结果。
你提到的网站似乎提供了这样的功能。在网络上搜索“HLR 查找 API”将为您提供更多结果。我对 CLX 服务有个人经验,并会推荐它。
What you need is called a HLR (Home Location Register) number lookup.
In their basic forms such APIs will expect a phone number in international format (example, +15121234567) and will return back their IMSI, which includes their MCC (gives you the country) and MNC (gives you the phone's carrier). The may even include the phone's current carrier (eg to tell if the phone is roaming). It may not work if the phone is currently out of range or turned off. In those cases, depending on the API provider, they may give you a cached result.
The site you mentioned seems to provide such functionality. A web search for "HLR lookup API" will give you plenty more results. I have personal experience with CLX's service and would recommend it.
这将是相当密集的代码,但只要 tnid.us 网站存在,您现在就可以自己做,无需 API:
为什么不在隐藏的浏览器窗口中打开带有电话号码 URL 的 IE?看起来 URL 的格式为 http:// tnid.us/search.php?q=########## 其中 # 代表数字。所以您需要一个文本框、一个标签和一个按钮。我将文本框称为“txtPhoneNumber”,将标签称为“lblCarrier”,按钮将调用下面的函数“OnClick”。
按钮函数使用 MSHtml.dll 和 SHDocVW.dll 创建 IE 实例,并对浏览器“对象”中的 HTML 进行页面抓取。然后你解析它。您必须首先安装 Visual Studio 2005 附带的互操作性程序集 (C:\Program Files\Common Files\Merge Modules\vs_piaredist.exe)。那么:
1>在 Visual Studio.NET 中创建一个新的 Web 项目。
2>添加对 SHDocVw.dll 和 Microsoft.mshtml 的引用。
3>在default.aspx.cs中,在顶部添加以下行:
4>添加以下功能:
由于某种原因,当我直接使用 tnid.us 网站时,我没有得到“当前电话公司”,但只有原始的。因此,您可能想让代码测试它返回的内容,即
我让它检查上面的任一内容,以便您返回一些内容。代码应该做的是找到之间的 HTML 区域
,
我让它查找该单词的索引
并添加该单词的字符以到达起始位置。我不记得 .indexOf 可以使用字符串还是只能使用字符。但你明白了,你或其他人可能可以找到一种方法来让它发挥作用。
您返回的文本是用字符代码编码的,因此您必须对其进行转换。我在上面给了你一些代码,应该有助于......它未经测试,完全来自我的头脑,但它应该有效或让你到达你要去的地方。
This would be pretty code intensive, but something you could do right now, on your own, without APIs as long as the tnid.us site is around:
Why not have IE open in a hidden browser window with the URL of the phone number? It looks like the URL would take the format of http://tnid.us/search.php?q=########## where # represents a number. So you need a textbox, a label, and a button. I call the textbox "txtPhoneNumber", the label "lblCarrier", and the button would call the function I have below "OnClick".
The button function creates the IE instance using MSHtml.dll and SHDocVW.dll and does a page scrape of the HTML that is in your browser "object". You then parse it down. You have to first install the Interoperability Assemblies that came with Visual Studio 2005 (C:\Program Files\Common Files\Merge Modules\vs_piaredist.exe). Then:
1> Create a new web project in Visual Studio.NET.
2> Add a reference to SHDocVw.dll and Microsoft.mshtml.
3> In default.aspx.cs, add these lines at the top:
4> Add the following function :
For some reason I don't get the "Current Phone Company" when I just use the tnid.us site directly, though, only the Original. So you might want to have the code test what it's getting back, i.e.
I have it checking for either one, above, so you get something back. What the code should do is to find the area of HTML between
and
I have it looking for the index of
and adding on the characters of that word to get to the starting position. I can't remember if you can use strings or only characters for .indexOf. But you get the point and you or someone else can probably find a way to get it working from there.
That text you get back is encoded with char codes, so you'd have to convert those. I gave you some code above that should assist in that... it's untested and completely from my head, but it should work or get you where you're going.
您是否在 tnid.us 结果页面上稍微往下看了一点?
Did you look just slightly farther down on the tnid.us result page?
[披露:我在 Twilio 工作]
您可以使用 Twilio Lookup。
如果您目前正在评估电话号码查找的服务和功能,我建议您尝试一下 Lookup 通过快速入门。
[Disclosure: I work for Twilio]
You can retrieve phone number information with Twilio Lookup.
If you are currently evaluating services and functionality for phone number lookup, I'd suggest giving Lookup a try via the quickstart.