手机号码归属地查询,手机号码归属地批量查询

手机号码归属地查询,手机号码归属地批量查询
在下载号段资源文件:https://download.csdn.net/download/linmilove/10734732

将以下内容存为aspx文件

<%@ Page Language="C#" AutoEventWireup="true" ClientIDMode="Static" %>


<%@ Import Namespace="System.Data" %>

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        }
    }
    protected void btnQuery_Click(object sender, EventArgs e)
    {
        string haoDuanPath = Server.MapPath("/") + "号段.txt";
        System.Text.StringBuilder sbResult = new StringBuilder();
        if (System.IO.File.Exists(haoDuanPath))
        {
            string[] haoDuanLins = System.IO.File.ReadAllLines(haoDuanPath, Encoding.Default);
            char[] huaHang = { '\r', '\n' };//换行
            string[] ChaHaoMa = txtMobile.Text.Split(huaHang, StringSplitOptions.RemoveEmptyEntries);

            //List<string> listChaHaoMa = txtMobile.Text.Split(huaHang, StringSplitOptions.RemoveEmptyEntries).ToArray<string>;

            Regex dReg = new Regex("1[3456789]\\d{9}");
            int count = 0;

            foreach (var item in haoDuanLins)
            {
                char[] separator = { ',', '', '', '', '    ' };
                string[] haoDuanColumn = item.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                if (haoDuanColumn.Length == 6)
                { 
                    foreach (var item2 in ChaHaoMa)
                    {
                        string[] chaColumn = item2.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                        if (dReg.IsMatch(chaColumn[0]))
                        {
                            if (chaColumn[0].Substring(0, 7).Equals(haoDuanColumn[1]))
                            {
                                sbResult.AppendFormat("{0},{1},{2},{3},{4},{5}", haoDuanColumn[2], haoDuanColumn[3], haoDuanColumn[4], haoDuanColumn[5], item2, Environment.NewLine);
                                count++; //从数组中删除当前号码
                            } 
                        }
                        else
                        {
                            sbResult.AppendFormat("未知归属地,未知运营商,未知区号,未知邮编,{0},{1}", item2, Environment.NewLine);
                            count++;
                            break;
                        } 
                    }
                } 
                if (count == ChaHaoMa.Length)
                {
                    break;
                }
            }
            foreach (var item in ChaHaoMa)
            {
                if (!sbResult.ToString().Contains(item))
                {
                    sbResult.AppendFormat("未知归属地,未知运营商,未知区号,未知邮编,{0},{1}", item, Environment.NewLine);
                }
            }
            txtResult.Text = sbResult.ToString();
        }
    }     
</script>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>手机号码归属地查询,手机号码归属地批量查询</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            请在下面的文本框中输入要查询的号码,格式为:号码,每行一个号码,每行第一列必需为手机号码,号码属性以逗号分隔):<br />
            示例如下:<asp:Button ID="btnQuery" runat="server" Text="批量查询" OnClick="btnQuery_Click" />
            <br />
            <asp:TextBox ID="txtMobile" runat="server" Height="227px" TextMode="MultiLine" Width="600px">15966667777,张三13877778888,李四</asp:TextBox>
            <br />
            查询结果如下,查询结果为:归属地,运营商,区号,邮编,原有数据<br />
            <asp:TextBox ID="txtResult" runat="server" Height="227px" TextMode="MultiLine" Width="600px"></asp:TextBox>

        </div>
    </form>
</body>
</html>

 

posted @ 2018-10-21 10:49  随便取个名字算了  阅读(2117)  评论(0编辑  收藏  举报