3

I want to get IMSI number of SIM of Android phone using command line.

Is there any adb command or any shell command in android for this???

I tried adb shell getprop ril.IMSI command in Samsung Galaxy ace, it works. It gives me IMSI number. But I tried the same command in Samsung Galaxy S3. It doesn't return anything.

I want to get IMSI number of SIM card in Samsung Galaxy S3 using command line only. (Not Android Application code) either using adb command or some shell command in Android.

Also, I know there is a simple code in JAVA to run in Android Application which gives IMSI number:

TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String imsi = mTelephonyMgr.getSubscriberId();

Can I somehow run this Android Java code from command line? This will also solve my problem.

Richard
  • 6,812
  • 5
  • 45
  • 60
user1865411
  • 69
  • 2
  • 2
  • 4

5 Answers5

8

To call TelephonyManager.getSubscriberId() in Android versions 5.x-7.x via adb shell run:

adb shell service call iphonesubinfo 7

This command no longer (i.e. on most 6.0+ devices) requires the device to be rooted.

For proper parsing of the service call command output on the device side and without external dependencies see my answer here

Also read Calling Android services from ADB shell for more details.

Alex P.
  • 30,437
  • 17
  • 118
  • 169
  • 2
    My phone is not Rooted. I checked with above command. But didn't work. It gives an big error saying:" ..Requires READ_PHONE_STATE: Neither user 2000 nor current process has android.permission .READ_PHONE_STATE" – user1865411 Feb 12 '13 at 07:16
2
adb shell getprop ril.iccid.sim1

If you want to know all data you can use only adb shell getprop, that shows you all of them, and you see that some items show you the IMSI like item ril.iccid.sim1 or persist.radio.cfu.iccid.0

Russia Must Remove Putin
  • 374,368
  • 89
  • 403
  • 331
j140781
  • 29
  • 1
  • @AmitaiFensterheim, Although the property manager might be standard in Android, access to it is certainly not. On my Samsung S6, `getprop` is a symlink to `toolbox`. It is likely to be different across vendors, let alone devices. Vendors may also choose to name their properties differently, or restrict access from userland altogether. – sherrellbc Sep 01 '16 at 13:43
0

You can use below code to get ccid using command from java code.

public static String getSIMCCIDByCmd() {
        try {
            Process getSimCCIDProc = Runtime.getRuntime().exec(new String[]{"getprop", "ril.iccid.sim1"});
            try (final BufferedReader b = new BufferedReader(new InputStreamReader(getSimCCIDProc.getInputStream()))) {
                String ccid = b.readLine();
                return ccid;
            } catch (final IOException e) {
                DadsHelper.LOG(TAG, "Exception while reading inputstream", e);
                return null;
            }
        }
        catch (Exception e) {
            DadsHelper.LOG(TAG,"Exception in getSIMCCID",e);

            return null;
        }
    }

Above code uses: getprop command to fetch value from property manager.

dpaksoni
  • 327
  • 3
  • 17
0
adb shell getprop persist.radio.ddssim.iccid

This worked for me on my Oneplus device. Like @j140781 mentioned, try adb shell getprop to get all the data, and then try to find items that start either with persist.radio. or ril.iccid.

Shubhral
  • 334
  • 3
  • 15
0

The following worked for me on a rooted Android 10 Moto G7 Plus:

adb shell
su

then once you are in the root shell:

service call iphonesubinfo 7 | tail -3 | sed s/\'\)// | awk '{print $NF}' | sed s/[\'\.]//g | tr -d \\n
Sasha Pachev
  • 5,162
  • 3
  • 20
  • 20