[Windows Mobile]取得 IMEI、IMSI

  • 32258
  • 0
  • 2013-04-15

[Windows Mobile]取得 IMEI、IMSI

 

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是行動用戶識別碼,用以識別某一行動通信網中的行動用戶。

本文學習目標

(1) 學習如何取得 IMEI 與 IMSI

(2) 由於 WM 修練大會即將進入尾聲,希望藉此問題,讓大家認識好用的 Library : OpenNETCF.TelephonybeeMobile4.net 如何使用

 

2. 使用 OpenNETCF.Telephony

2.1 前置作業

首先介紹如何使用 OpenNETCF.Telephony 取得 IMEI 與 IMSI,首先進行下載,並且將 OpenNetCF.Telephony 加入專案裡。下載網址

image image image

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

image image image

 

並於程式中 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;
        }
    }
}

 

 

3. 使用 beeMobile4.net

3.1 介紹

beeMobile4.net 其實最有名是關於 Compact Framework UI 的部份,有興趣的可以到 此網頁 看看其介面設定,但幾乎都是要收費的

screen.php1 4 3

其中 beeMobile4.net 的 Free Utils Library 是免費的,可以使用此 Library 取得 IMEI 與 IMSI

除了取得 IMEI 與 IMSI 外,還可以做以下事情

  • Resetting the device
  • Keeping the back-light on
  • Finding out the path to application's executable
  • Getting the device's IMSI and IMEI
  • Changing Volume level
  • Making Screenshot

 

3.2 前置作業

首先將 Free Utils 下載,並且將 Free Utils 加入專案裡。下載網址

image image image

將 Utils 重建後,產生的 BeeMobile.Util.dll 加入參考中

image image image

 

並於程式中 using


using BeeMobile.TAPI;

 

3.3 程式碼

於 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 BeeMobile.TAPI;

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

        private void btnGetInfo_Click(object sender, EventArgs e)
        {
            txtIMSI.Text = PhoneInfo.GetIMSI();  // IMSI
            txtIMEI.Text = PhoneInfo.GetIMEI();  // IMEI
        }
    }
}

 

4. 結語

其實取得 IMEI 跟 IMSI 的部分,這兩個 Library 都是透過調用 Windows API 取得資訊,而除了直接使用 Library 外,建議可以看看原始碼是怎麼寫的。

例如 Free Utils Library,其中 Reset Device 的程式碼與 MSDN 中的 HOW TO:重設裝置 幾乎一樣

image image

而取得應用程式目錄的部份,其實是使用此程式碼


Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);

 

5. 參考

SIM,PIN,PUK,IMEI,ICCID,Ki,IMSI,SMSP概念

HOWTO: Retrieve the IMEI and IMSI of a device

獲取IMEI手機的問題

lineGetGeneralInfo

BeeMobile for Windows Mobile

"How To" Series: Retrieving IMSI and IMEI on Windows Mobile