是否有 android shell 或 adb 命令可以用来获取设备的 IMEI/MEID?

发布于 2024-11-26 19:54:49 字数 73 浏览 1 评论 0原文

我可以运行一些 adb 或 android shell 命令来返回设备的 IMEI 或 MEID 号码吗?最好这就是返回的全部内容。

Is there some adb or android shell command that I could run that would return a device's IMEI or MEID number? Preferably that's all that would be returned.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

寂寞美少年 2024-12-03 19:54:49

我想出了如何做到这一点。您需要在 shell 中运行 adb shell dumpsys iphonesubinfo。它会给你比你需要的多一点的信息,但它也会返回 IMEI 或 MEID 号码。

编辑(2017):在 Android 5.0+ 中,您需要使用 service call 命令。有关详细信息,请参阅 这里

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.

清旖 2024-12-03 19:54:49

对于 IMEI,您可以使用:

adb shell service call iphonesubinfo 1 | awk -F "'" '{print $2}' | sed '1 d' | tr -d '.' | awk '{print}' ORS=

For IMEI you can use:

adb shell service call iphonesubinfo 1 | awk -F "'" '{print $2}' | sed '1 d' | tr -d '.' | awk '{print}' ORS=
匿名的好友 2024-12-03 19:54:49

以下 ADB 命令可帮助我获取 IMEI:

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

The following ADB command works for me to get the IMEI:

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

满栀 2024-12-03 19:54:49

对于 ESN,您可以

拨打 iphonesubinfo 16 进行服务,

至少它会在 Motorola Photon Q 上为我提供正确的信息。

要清理它(假设您的设备上有 shell,并且那里有一个功能强大的 busybox,如果没有,我强烈推荐一个)

    service call iphonesubinfo 16 | busybox awk -F "'" '{print $2}' | busybox sed 's/[^0-9A-F]*//g' | busybox tr -d '\n' && echo

:带清理的 MEID:

service call iphonesubinfo 1 | busybox awk -F "'" '{print $2}' | busybox sed 's/[^0-9A-F]*//g' | busybox tr -d '\n' && echo

For ESN you can do

service call iphonesubinfo 16

at least it gives me the right one on Motorola Photon Q.

To clean it up (assuming you have shell on the device and have a capable busybox there, if not I highly recommend one):

    service call iphonesubinfo 16 | busybox awk -F "'" '{print $2}' | busybox sed 's/[^0-9A-F]*//g' | busybox tr -d '\n' && echo

For MEID with cleanup:

service call iphonesubinfo 1 | busybox awk -F "'" '{print $2}' | busybox sed 's/[^0-9A-F]*//g' | busybox tr -d '\n' && echo
温柔嚣张 2024-12-03 19:54:49

这适用于我的 Nexus 5 和 moto 5G。

输出:

[build.id]: [M4B30X]
[build.version.release]: [6.0.1]
[build.version.sdk]: [23]
[build.version.security_patch]: [2016-10-05]
[product.brand]: [google]
[product.manufacturer]: [LGE]
[product.model]: [Nexus 5]
[product.name]: [hammerhead]
[serialno]: [05xxxxxxxxxxx4]
[device.imei]: [xxxxxxxxxxxx]
[device.phonenumber]: [+xxxxxxxxxx]

脚本get.deviceinfo.bash

#!/bin/bash
# Get the device properties
adb shell getprop | grep "model\|version.sdk\|manufacturer\|ro.serialno\|product.name\|brand\|version.release\|build.id\|security_patch" | sed 's/ro\.//g'
# get the device ime
echo "[device.imei]: [$(adb shell service call iphonesubinfo 1 | awk -F "'" '{print $2}' | sed '1 d'| tr -d '\n' | tr -d '.' | tr -d ' ')]"
# get the device phone number
echo "[device.phonenumber]: [$(adb shell service call iphonesubinfo 19 | awk -F "'" '{print $2}' | sed '1 d'| tr -d '\n' | tr -d '.' | tr -d ' ')]"

它需要:

  • UBS 调试开启(开发人员选项)
  • adb (< a href="https://developer.android.com/studio/releases/platform-tools.html#download" rel="nofollow noreferrer">Android SDK 平台工具)

This works for me on my nexus 5 and moto 5G.

output:

[build.id]: [M4B30X]
[build.version.release]: [6.0.1]
[build.version.sdk]: [23]
[build.version.security_patch]: [2016-10-05]
[product.brand]: [google]
[product.manufacturer]: [LGE]
[product.model]: [Nexus 5]
[product.name]: [hammerhead]
[serialno]: [05xxxxxxxxxxx4]
[device.imei]: [xxxxxxxxxxxx]
[device.phonenumber]: [+xxxxxxxxxx]

Script: get.deviceinfo.bash

#!/bin/bash
# Get the device properties
adb shell getprop | grep "model\|version.sdk\|manufacturer\|ro.serialno\|product.name\|brand\|version.release\|build.id\|security_patch" | sed 's/ro\.//g'
# get the device ime
echo "[device.imei]: [$(adb shell service call iphonesubinfo 1 | awk -F "'" '{print $2}' | sed '1 d'| tr -d '\n' | tr -d '.' | tr -d ' ')]"
# get the device phone number
echo "[device.phonenumber]: [$(adb shell service call iphonesubinfo 19 | awk -F "'" '{print $2}' | sed '1 d'| tr -d '\n' | tr -d '.' | tr -d ' ')]"

It requires:

一绘本一梦想 2024-12-03 19:54:49

对于IMEI,也许这个命令更容易理解

db -s <device id> shell  service call iphonesubinfo 1 | cut -c 52-66 | tr -d '.[:space:]'
  • db -sshell 服务调用 iphonesubinfo 1 获取完整结果,例如
Result: Parcel(
      0x00000000: 00000000 0000000f 00350033 00340037 '........3.5.7.4.'
      0x00000010: 00350032 00370030 00310032 00390039 '2.5.0.7.2.1.9.9.'
      0x00000020: 00370034 00000032                   '4.7.2...        ')
  • cut -c 52-66 使用上面的示例
........3.5.7.4
2.5.0.7.2.1.9.9
4.7.2...       
  • tr -d ' 修剪除 52-66 之外的所有列.[:space:]' 修剪掉任何 '.'和空格,使用上面的示例
357425072199472

警告
这种方法的缺点是它很脆弱,因为输出必须始终采用相同的格式,具有完全相同的列。我在 CentOs 和 OS X 上验证了它,但 adb 版本的更新可能会通过调整输出中的空格来破坏此命令。

For the IMEI, maybe this command is easier to understand

db -s <device id> shell  service call iphonesubinfo 1 | cut -c 52-66 | tr -d '.[:space:]'
  • db -s <device id> shell service call iphonesubinfo 1 gets the full result, for example
Result: Parcel(
      0x00000000: 00000000 0000000f 00350033 00340037 '........3.5.7.4.'
      0x00000010: 00350032 00370030 00310032 00390039 '2.5.0.7.2.1.9.9.'
      0x00000020: 00370034 00000032                   '4.7.2...        ')
  • cut -c 52-66 trims away all columns except 52-66, using the above example
........3.5.7.4
2.5.0.7.2.1.9.9
4.7.2...       
  • and tr -d '.[:space:]' trims off any '.' and white space, using the example above
357425072199472

Warning
A downside of this approach is that it is brittle, in the sense that the output must always be in the same format, having the exact same columns. I verified it on CentOs and OS X, but an update to the adb version could break this command simply by adjusting the whitespace in the output.

夢归不見 2024-12-03 19:54:49

IMEI-
adb shell 服务调用 iphonesubinfo 1 | awk -F "'" '{print $2}' | awk -F "'" '{print $2}' | sed '1 d'| sed 's/.//g' | sed 's/.//g' | awk '{print}' ORS=''

Android ID=

adb shell 设置获取安全 android_id

IMEI-
adb shell service call iphonesubinfo 1 | awk -F "'" '{print $2}' | sed '1 d'| sed 's/.//g' | awk '{print}' ORS=''

Android ID=

adb shell settings get secure android_id

烟燃烟灭 2024-12-03 19:54:49

由于 iphonesubinfo 1 命令在许多设备上不起作用,这里有一个小解决方法,应该可以在大多数 Android 版本以及已 root 和未 root 的设备上一致工作:

如果您已经有一个自己的应用程序,可以安装在您想要了解 IMEI 的设备上,将此 BroadcastReceiver 添加到您的应用:

public class GetImeiReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String imei = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
        setResultData(imei);
    }

}

以及 AndroidManifest.xml

<receiver android:name=".GetImeiReceiver">
  <intent-filter>
    <action android:name="com.myapp.GET_IMEI"/>
  </intent-filter>
</receiver>

通过 ADB 调用您的接收器:

adb shell am broadcast -a com.myapp.GET_IMEI

...并且输出将会是一些东西例如:

Broadcast completed: result=0, data="000000000000000"

...其中 data 是设备 IMEI。

如果您没有现有的应用程序来集成此解决方案,我创建了这个简单的应用程序,其中包含所需的代码:
https://github.com/saschoar/android-imei-getter(还包括APK 和完整说明)。

As the iphonesubinfo 1 command does not work on many devices, here is a little workaround that should work consistently on most Android versions and on rooted and unrooted devices:

If you already have an own app that you can install on the device that you want to know the IMEI from, add this BroadcastReceiver to your app:

public class GetImeiReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String imei = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
        setResultData(imei);
    }

}

and to the AndroidManifest.xml:

<receiver android:name=".GetImeiReceiver">
  <intent-filter>
    <action android:name="com.myapp.GET_IMEI"/>
  </intent-filter>
</receiver>

Call your receiver over ADB:

adb shell am broadcast -a com.myapp.GET_IMEI

...and the output will be something like:

Broadcast completed: result=0, data="000000000000000"

...where data is the device IMEI.

If you have don't have an existing app to integrate this solution into, I created this simple one which includes the required code:
https://github.com/saschoar/android-imei-getter (also includes the APK and full instructions).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文