iT邦幫忙

DAY 13
2

Windows Mobile系列 第 13

[Windows Mobile]撰寫程式取得行動裝置的 IMEI、IMSI

撰寫程式取得行動裝置的 IMEI (International Mobile Equipment Identification Number) 與 IMSI (International Mobile Subscriber Identification Number)
更多文章,請到我在點部落所建立的部落格「.NET菜鳥自救會」閱讀
http://www.dotblogs.com.tw/chou/

  1. 簡介
    如何取得行動裝置的 IMEI (International Mobile Equipment Identification Number) 與 IMSI (International Mobile Subscriber Identification Number) 是在各大討論版常見的問題,首先,什麼是 IMEI 跟 IMSI ?
    國際行動裝置識別碼(IMEI)是區別行動裝置的標誌,儲存在行動裝置中,可用於監控被竊或無效的行動裝置。其總長為15位,每位數字僅使用0~9的數字。其中TAC代表型號裝配碼,由歐洲型號標準中心分配;FAC代表裝配廠家號碼;SNR為產品序號,用於區別同一個TAC和FAC中的每台行動裝置;SP是備用編碼。
    國際行動用戶識別碼(IMSI)是區別行動裝置用戶的標誌,儲存在SIM卡中,可用於區別行動裝置用戶的有效訊息。其總長度不超過15位,同樣使用0~9的數字。 其中MCC是行動裝置用戶所屬國家代號,佔3位數字;MNC是行動網號碼,最多由兩位數字組成,用於識別行動裝置用戶所歸屬的行動通信網;MSIN是行動用戶識別碼,用以識別某一行動通信網中的行動用戶。

  2. 使用 OpenNETCF.Telephony
    2.1 前置作業
    首先介紹如何使用 OpenNETCF.Telephony 取得 IMEI 與 IMSI,首先進行下載,並且將 OpenNetCF.Telephony 加入專案裡。下載網址http://tapi.codeplex.com/



    將 OpenNetCF.Telephony 重建後,產生的 OpenNETCF.Telephony.dll 加入參考中


並於程式中 using

using OpenNETCF.Telephony; 

2.2 程式碼

於 Form 中加入 Button (Name :btnGetInfo,點擊後顯示 IMEI 與 IMSI)與兩個 TextBox ( Name : txtIMSI,顯示 IMSI;Name : txtIMEI,顯示 IMEI)

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using OpenNETCF.Telephony;  

namespace SmartDeviceTAPI
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnGetInfo_Click(object sender, EventArgs e)
        {
            LineGeneralInfo deviceInfo = null;

            if (GetDeviceInfo(ref deviceInfo))
            {
                txtIMSI.Text = deviceInfo.SubscriberNumber;  // IMSI
                txtIMEI.Text = deviceInfo.SerialNumber;  // IMEI
            }
        }

        private static bool GetDeviceInfo(ref LineGeneralInfo deviceInfo)
        {
            bool result = false;
            Telephony phone = new Telephony();

            try
            {
                phone.Initialize();
                if (deviceInfo == null)
                {
                    deviceInfo = new LineGeneralInfo(512);
                }

                BitConverter.GetBytes(deviceInfo.Data.Length).CopyTo(deviceInfo.Data, 0);
                using (Line line = phone.CreateLine(0, MediaMode.InteractiveVoice, CallPrivilege.Monitor))
                {
                    if (0 == NativeMethods.lineGetGeneralInfo(line.hLine, deviceInfo.Data))
                    {
                        deviceInfo.Load();
                        result = true;
                    }
                }
            }
            finally
            {
                phone.Shutdown();
            }
            return result;
        }
    }
}

上一篇
[Windows Mobile]使用 Microsoft Tag Reader 軟體讀取 Tag 資訊
下一篇
[Windows Mobile]取得行動裝置的識別碼 UniqueID
系列文
Windows Mobile41
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言