How to Get Imsi Number in Android Using Command Line

Read IMSI information via ADB on Android 12

If your apk's targetsdk <30, you can get IMSI by the following method without any permission in android 11.

Uri uri = Uri.parse("content://telephony/siminfo");
Cursor cursor = null;
ContentResolver contentResolver = getApplicationContext().getContentResolver();
cursor = contentResolver.query(uri,
new String[]{"_id", "sim_id", "imsi","icc_id","number","display_name"}, "0=0",
new String[]{}, null);
if (null != cursor) {
while (cursor.moveToNext()) {
String icc_id = cursor.getString(cursor.getColumnIndex("icc_id"));
String imsi_id = cursor.getString(cursor.getColumnIndex("imsi"));
String phone_num = cursor.getString(cursor.getColumnIndex("number"));
String display_name = cursor.getString(cursor.getColumnIndex("display_name"));
int sim_id = cursor.getInt(cursor.getColumnIndex("sim_id"));
int _id = cursor.getInt(cursor.getColumnIndex("_id"));
Log.d("Q_M", "icc_id-->" + icc_id);
Log.d("Q_M", "imsi_id-->" + imsi_id);
Log.d("Q_M", "phone_num-->" + phone_num);
Log.d("Q_M", "sim_id-->" + sim_id);
Log.d("Q_M", "display_name-->" + display_name);

Is there an android shell or adb command that I could use to get a device's IMEI/MEID?

I figured out how to do this. You need to run adb shell dumpsys iphonesubinfo in a shell. It will give you a bit more than you need, but it will also return IMEI or MEID number.

Edit (2017): In Android 5.0+ you'll need to use the service call command. More info about that can be found here.

How to get the phone number of an android phone via adb?

iphonesubinfo service "keeps track" of the subscriber information including phone numbers. Unfortunately iphonesubinfo service does not implement the dump() method so dumpsys shows nothing. You will have to use service call command to call IPhoneSubInfo.getLine1Number() or IPhoneSubInfo.getMsisdn() instead

Depending on the android version and your carrier one or two of the following commands will tell you the phone number (service call commands require root privileges):

service call iphonesubinfo 4
service call iphonesubinfo 5
service call iphonesubinfo 6
service call iphonesubinfo 7
service call iphonesubinfo 8

If you want to find out the proper code for your specific device - download the script from Calling Android services from ADB shell post and run it like this:

./ iphonesubinfo | grep getLine1Number


Transaction codes for Android 5.0:

service call iphonesubinfo 11 # getLine1Number()
service call iphonesubinfo 15 # getMsisdn()

Transaction codes for Android 5.1:

service call iphonesubinfo 13 # getLine1Number()
service call iphonesubinfo 17 # getMsisdn()

Related Topics

Leave a reply