获取sim卡IMSI信息

public struct GeneralInfo { public string Manufacturer;//制造商 public string Model;//机型 public string Revision;//版本 public string SerialNumber;//序列号 public string SubscriberNumber;//用户电话 } class ControlTapi { [DllImport("cellcore.dll")] private static extern int lineGetGeneralInfo(IntPtr hLine, byte[] lpLineGeneralInfo); ///

/// 调用cellcore.dll获取sim卡的综合信息 /// /// /// private GeneralInfo GetGeneralInfo(Line l) { GeneralInfo lgi = new GeneralInfo(); byte[] buffer = new byte[512]; BitConverter.GetBytes(512).CopyTo(buffer, 0); if (lineGetGeneralInfo(l.hLine, buffer) != 0) { throw new System.ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error(), "TAPI Error: " + System.Runtime.InteropServices.Marshal.GetLastWin32Error().ToString("X")); } int subscsize = BitConverter.ToInt32(buffer, 44); int subscoffset = BitConverter.ToInt32(buffer, 48); lgi.SubscriberNumber = System.Text.Encoding.Unicode.GetString(buffer, subscoffset, subscsize).ToString(); lgi.SubscriberNumber = lgi.SubscriberNumber.Replace("/0", ""); int sersize = BitConverter.ToInt32(buffer, 36); int seroffset = BitConverter.ToInt32(buffer, 40); lgi.SerialNumber = System.Text.Encoding.Unicode.GetString(buffer, seroffset, sersize).ToString(); lgi.SerialNumber = lgi.SerialNumber.Replace("/0", ""); return lgi; } /// /// 获取sim卡的IMSI /// /// /// 一个imsi (国际移动用户识别)是一个独特的15位数字代码用于识别个人用户对GSM网络。 ///An IMSI consists of three components:一个imsi包括三个组成部分: ///Mobile Country Code (MCC)移动国家代码( MCC )的 ///Mobile Network Code (MNC)移动网络代码(跨国公司) ///Mobile Subscriber Identity Number (MSIN)移动用户识别号码( msin ) public static string GetIMSINumber() { string result = ""; try { Tapi t = new Tapi(); t.Initialize(); Line l = t.CreateLine(0, LINEMEDIAMODE.INTERACTIVEVOICE, OpenNETCF.Tapi.LINECALLPRIVILEGE.MONITOR); ControlTapi ctapi = new ControlTapi(); GeneralInfo gi = ctapi.GetGeneralInfo(l); result = gi.SubscriberNumber; l.Dispose(); t.Shutdown(); } catch// (Exception ex) { result = ""; } return result; }

这段代码是网上流传的,不是很全,请大家帮忙补写……

Tapi t = new Tapi();
                t.Initialize();

Line l ……

你可能感兴趣的:(获取sim卡IMSI信息)