Get SIM card number (imsi)

Source: Internet
Author: User

At the end of the week, I had to write a blog, but after thinking about it, I suddenly found that I didn't do anything this week, and I didn't know what to write. Finally, I suddenly found this code on the desktop, if you use imsi, you can write it here. You can play the game as soon as you finish writing it, and the game time is up again. Dota ......

 

Imsi, which is also the SIM card number, is the unique identifier of the user. The imsi number structure is as follows:

MCC ------------- MNC ------------------ msin

MCC = Mobile country number, which consists of three digits and uniquely identifies the country to which a mobile customer belongs. China is 460.

MNC = mobile network number, composed of two digits, used to identify the mobile network that a mobile customer belongs. The GSM plmn network of the Post and Telecommunications Department is 00, and the "China Unicom Company" gsmplmn is 0l.

Msin = Mobile customer identification code, which consists of 11 digits. Uniquely identifies China Mobile clients in China's GSM mobile communication network.

To obtain imsi, you can use linegetgeneralinfo in extapi. It returns various hardware information to its second structure member, namely, the linegeneralinfo structure.

The structure is defined as follows:

Typedef struct linegeneralinfo_tag {

DWORDDwtotalsize;

DWORDDwneededsize;

DWORDDwusedsize;

DWORDDwmanufacturersize;

DWORDDwmanufactureroffset;

DWORDDwmodelsize;

DWORDDwmodeloffset;

DWORDDwrevisionsize;

DWORDDwrevisionoffset;

DWORDDwserialnumbersize;

DWORDDwserialnumberoffset;

DWORDDwsubscribernumbersize;

DWORDDwsubscribernumberoffset;

} Linegeneralinfo, * lplinegeneralinfo;

The information in it is clear. For example, to obtain imsi, add the offset indicated by dwsubscribernumberoffset to the first address of the structure. That is:

Lptstr lstr = (tchar *) (byte *) plinedevcaps + plinedevcaps-> dwlinenameoffset );

To use linegetgeneralinfo, you must initialize the program in the TAPI order and perform necessary operations to call linegetgeneralinfo.

To use TAPI, the approximate sequence is:

Lineinitializeex

Linenegotiateapiversion

Lineopen

After these functions are called, you can prepare for obtaining imsi.

To obtain information such as imsi and IMEI, you must obtain it from the device line named "cellular line". Therefore, you must enumerate all the device lines at the beginning, find the line named "cellular line" and use the handle of the line as the first parameter of linegeneralinfo.

Before using linegeneralinfo, set its dwtotalsize to its own size, and call linegeneralinfo once, in the dwneededsize structure of linegeneralinfo, the space required to store all information is returned. At this time, you only need to apply for a piece of memory based on this Member, point to it with a linegeneralinfo pointer, and then call linegetgeneralinfo again, at this time, it contains all kinds of useful information. You can get whatever you want.

Paste the following simple code:

  1. Int winapi winmain (hinstance,
  2. Hinstance hprevinstance,
  3. Lptstr lpcmdline,
  4. Int ncmdshow)
  5. {
  6. Lptstr lpszimsi;
  7. Lineinitializeexparams lineextparams;
  8. Lineextparams. dwtotalsize = sizeof (lineextparams );
  9. Lineextparams. dwoptions = lineinitializeexoption_useevent;
  10. DWORD dwapiversion = tapi_current_version;
  11. Hlineapp;
  12. DWORD dwnumdevs;
  13. Lineinitializeex (& hlineapp, null, null, _ T ("mengge"), & dwnumdevs, & dwapiversion, & lineextparams );
  14. DWORD dwtspilinedeviceid = 0;
  15. For (DWORD dwcurrentdevid = 0; dwcurrentdevid <dwnumdevs; dwcurrentdevid ++)
  16. {
  17. Lineextensionid;
  18. If (linenegotiateapiversion (hlineapp, dwcurrentdevid,
  19. Tapi_api_low_version, tapi_current_version,
  20. & Dwapiversion, & lineextensionid) = 0)
  21. {
  22. Linedevcaps;
  23. Linedevcaps. dwtotalsize = sizeof (linedevcaps );
  24. If (: linegetdevcaps (hlineapp, dwcurrentdevid,
  25. Dwapiversion, 0, & linedevcaps) = 0)
  26. {
  27. Byte * plinedevcapsbytes = new byte [linedevcaps. dwneededsize];
  28. If (0! = Plinedevcapsbytes)
  29. {
  30. Linedevcaps * plinedevcaps = (linedevcaps *) plinedevcapsbytes;
  31. Plinedevcaps-> dwtotalsize = linedevcaps. dwneededsize;
  32. If (: linegetdevcaps (hlineapp, dwcurrentdevid,
  33. Dwapiversion, 0, plinedevcaps) = 0)
  34. {
  35. Lptstr lstr = (tchar *) (byte *) plinedevcaps + plinedevcaps-> dwlinenameoffset );
  36. If (! _ Tcscmp (celltsp_linename_string, lstr ))
  37. {
  38. Dwtspilinedeviceid = dwcurrentdevid;
  39. Delete [] plinedevcapsbytes;
  40. Break;
  41. }
  42. }
  43. Delete [] plinedevcapsbytes;
  44. }
  45. }
  46. }
  47. }
  48. Hline = NULL;
  49. If (: lineopen (hlineapp, dwtspilinedeviceid,
  50. & Hline, dwapiversion, 0, 0,
  51. Linecallprivilege_owner, linemediamode_datamodem, 0 ))
  52. {
  53. : Lineshudown (hlineapp );
  54. Return false;
  55. }
  56. Linegeneralinfo lvigeneralinfo;
  57. Lvigeneralinfo. dwtotalsize = sizeof (lvigeneralinfo );
  58. Long lres =: linegetgeneralinfo (hline, & lvigeneralinfo );
  59. If (lres! = 0 & lres! = Lineerr_structuretoosmall)
  60. {
  61. DWORD dd = getlasterror ();
  62. : Lineclose (hline );
  63. : Lineshudown (hlineapp );
  64. Return false;
  65. }
  66. Lplinegeneralinfo plvigeneralinfo;
  67. Lptstr tssubscribernumber;
  68. Lpbyte plinegeneralinfobytes = NULL;
  69. Plinegeneralinfobytes = new byte [lvigeneralinfo. dwneededsize];
  70. Plvigeneralinfo = (lplinegeneralinfo) plinegeneralinfobytes;
  71. If (plinegeneralinfobytes! = NULL)
  72. {
  73. Plvigeneralinfo-> dwtotalsize = lvigeneralinfo. dwneededsize;
  74. If (lres =: linegetgeneralinfo (hline, plvigeneralinfo ))! = 0)
  75. {
  76. : Lineclose (hline );
  77. : Lineshudown (hlineapp );
  78. Return false;
  79. }
  80. Else
  81. {
  82. Tchar szunavailable [] = l "unavailable ";
  83. If (plvigeneralinfo-> dwsubscribernumbersize)
  84. {
  85. Tssubscribernumber = (wchar *) (byte *) plvigeneralinfo)
  86. + Plvigeneralinfo-> dwsubscribernumberoffset); // imsi is obtained here.
  87. }
  88. Else
  89. {
  90. Tssubscribernumber = szunavailable;
  91. }
  92. }
  93. }
  94. Delete [] plinegeneralinfobytes;
  95. Return 10;
  96. }

 

Note: I failed to use this program on some simulators. After debugging, I found that no device line named "cellular line" was found. I don't know why ......

There is an exapi example in the SDK, which contains information such as imsi, IMEI, manufacturer, and software version.

Dotaing .....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.