8

I am working with ADB on my Samsung Galaxy device. I want to get the IMEI number of the device using ADB, but I have been unable to do that.

I tried the following:

adb shell dumpsys iphonesubinfo

but it returns nothing.

I also tried with Service Call Command:

adb shell service call iphonesubinfo

but it gives me a strange result like this:

Result: Parcel(                                                        
0x00000000: 00000000 0000000f 00350033 00390038 '........3.5.8.9.'    
0x00000010: 00320037 00380030 00350034 00350031 '7.2.0.8.4.5.1.5.'   
0x00000020: 00300031 00000033                   '1.0.3...        ')

Can anybody help me out with this?

3
  • You could try calling an intent like below: am start -a android.intent.action.DIAL -d "tel:*%2306%23"
    – esQmo_
    Commented Apr 4, 2018 at 22:31
  • @esQmo_ But that will just open Dialer wirh IMEI getting code. I don't user to manually do anything.
    – yash
    Commented Apr 5, 2018 at 8:07
  • 1
    Related: How to get 2nd IMEI number using adb? Commented Jul 21, 2020 at 6:39

7 Answers 7

3
+50

Try putting this code in to a .bat file and running it:

@echo off
setlocal enabledelayedexpansion
for /f "tokens=6*" %%a in ('adb shell "service call iphonesubinfo 1 ^| grep -m 1 \"'\""') do (
set imei1=%%a)
for /f "tokens=6*" %%b in ('adb shell "service call iphonesubinfo 1 ^| grep -m 2 \"'\""') do (
set imei2=%%b)
for /f "tokens=4*" %%c in ('adb shell "service call iphonesubinfo 1 ^| grep -m 3 \"'\""') do (
set imei3=%%c) 
set imei=!imei1!!imei2!!imei3!
echo !imei! > imei.txt
for /f "delims=" %%d in (imei.txt) do (
set DeviceIMEI=%%d
set DeviceIMEI=!DeviceIMEI:'=!
set DeviceIMEI=!DeviceIMEI:.=!
set OIMEI=Phone IMEI  !DeviceIMEI!
)
echo %OIMEI%
pause

I got it from this StackOverflow thread: https://stackoverflow.com/a/34362809/8173870

8

Given the tag , I'm assuming you have or are targeting Android Nougat. Android Nougat comes with toybox which acts as an alternative to busybox and has some useful utilities. I managed to use those tools to print IMEI like this:

adb shell
service call iphonesubinfo 1 | toybox cut -d "'" -f2 | toybox grep -Eo '[0-9]' | toybox xargs | toybox sed 's/\ //g'

Since you wouldn't be getting an interactive shell when using a script or an app, you can pass the commands like this:

adb shell "service call iphonesubinfo 1 | toybox cut -d \"'\" -f2 | toybox grep -Eo '[0-9]' | toybox xargs | toybox sed 's/\ //g'"
0
4

The following ADB command works on my Windows PC to get clear IMEI result:

adb shell "service call iphonesubinfo 4 | cut -c 52-66 | tr -d '.[:space:]'"

2
  • thanks for sharing the best code. I get IMEI result by this code, but it's only show 1st IMEI. If I want to get result 2nd IMEI what should we put the code ? thanks for Answers. Commented Dec 3, 2020 at 17:50
  • 1
    I changed the code from iphonesubinfo 1 to iphonesubinfo 4, which is the correct service code to get the full IMEI. So try: adb shell "service call iphonesubinfo 4 | cut -c 52-66 | tr -d '.[:space:]'", and see if you get also IMEI 2.
    – Devlpr
    Commented Dec 6, 2020 at 17:58
3

You may not have realized it, but you've actually posted the answer to your own question:

  Result: Parcel(                                                        
0x00000000: 00000000 0000000f 00350033 00390038 '........3.5.8.9.'    
0x00000010: 00320037 00380030 00350034 00350031 '7.2.0.8.4.5.1.5.'   
0x00000020: 00300031 00000033                   '1.0.3...        ')

Specifically, the portion to the right:

'........3.5.8.9.'
'7.2.0.8.4.5.1.5.'         
'1.0.3...        '

Simply put it all on one line and remove the single quotes and it becomes:

........3.5.8.9.7.2.0.8.4.5.1.5.1.0.3...

Now remove the dots and you get:

358972084515103 

(aka your IMEI number)

3

esim imei is available via:

input keyevent KEYCODE_CALL;
sleep 1;
input text '*#06#'; 
uiautomator dump --compressed /dev/stdout\
    |tr ' ' '\n'\
    |awk -F'"' '{print $2}'|grep "^[0-9]\{15\}$" \
    |nl -w 1 -s':'\
    |sed 's/^/IMEI/g'
IMEI1:xxxxxxxxxxxxx
IMEI2:xxxxxxxxxxxxx
1
  • This is the only solution that worked for me on Android 12. Note that I have a non-stock dialer installed, so I had to select the dialer from the screen - i.e. this is interactive. But it's still better than trying to copy the IMEI to the computer after checking with *#06#.
    – dotancohen
    Commented Jul 30 at 18:04
2

Using android-svc:

android-svc --adb call 'iphonesubinfo.getDeviceId();'

would return something like this:

358972084515103
2

adb shell dumpsys iphonesubinfo works only for phones below Android 5 Lolipop.

Because Android Nougat is over 5.0, you need: adb shell service call iphonesubinfo 1 | awk -F "'" '{print $2}' | sed '1 d' | tr -d '.' | awk '{print}' ORS=

2
  • i am using Windows as OS so it gives me Error awk not found. What would be Equivalent of awk in windows Command Prompt?
    – yash
    Commented Apr 5, 2018 at 8:01
  • 1
    There is no equivalent to awk on Windows. But you can simply install all the *nix tools also on Windows. A very simple way to do that is scoop. Or you have to create a windows tool that parses the command-line result without those tools.
    – Robert
    Commented Apr 10, 2018 at 9:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .