adb 查询手机信息
# 显示当前 ip
.\adb.exe shell ip addr show wlan0
 10.168.90.72
 link/ether 为当前 MAC 地址 
 brd 为当前广播地址 

# 显示外网 ip 
.\adb.exe shell curl -s http://members.3322.org/dyndns/getip
.\adb.exe shell curl http://ipinfo.io

# 显示 路由
.\adb.exe shell ip route

# 查看访问路由 
.\adb.exe shell ip route get 144.144.144.144
.\adb.exe shell ip route get 8.8.8.8

# 查看手机 id 
.\adb.exe shell  settings get secure android_id

# 获取手机 serial no
.\adb.exe shell getprop ro.serialno

# 获取手机真实 serial no
.\adb.exe shell getprop ro.usedno

# 手机构建信息
adb devices | Select-String .*\t | % { $_.Matches.Value.Trim() } | % { Write-Host "$_`t" -NoNewLine ;  adb -s $_ shell  getprop ro.commit }

# 手机温度
.\adb.exe shell dumpsys thermalservice | Select-String 'Thermal Status: \d+' | % { $_.Matches[0].Value }

# 手机当前时间与时区
adb -s $mobileAddress shell ' date "+%Y-%m-%d %H:%M:%S %Z %z"'

# 摄像头
$info = .\adb.exe -s $_ shell ' dumpsys media.camera | grep Facing '        
$output = "$_ $info"            
if ( -not (($info -like '*Back*' ) -and ($info -like '*Front*' )) ) {
    Write-Host $output -ForegroundColor Red            
    $lostDeviceIds += $_ 
} 
else { 
    echo $output 

# 手机信号强度
adb -s 1C021FDF600CU1 shell "dumpsys telephony.registry|grep mSignalStrength|cut -f5 -d,|cut -f3,4 -d' '"
取 rsrp 与 rsrq 数值
RSRP (Reference Signal Received Power): 参考信号接收功率
优秀: > -80dBm, 良好: -80dBm 到 -90dBm, 一般: -90dBm 到 -100dBm, 差: < -100dBm
RSRQ (Reference Signal Received Quality): 参考信号接收质量
优秀: > -10dB, 良好: -10dB 到 -15dB, 一般: -15dB 到 -20dB, 差: < -20dB

# 获取手机序列号及 eth0 mac 地址 
.\adb.exe devices | ? { $_ -match '\bdevice\b' } | Select-String [\d\.]+ | % Matches | % Value  | Sort-Object | % {

    $id = .\adb.exe -s $_ shell "getprop ro.serialno"
    $mac =.\adb.exe -s $_ shell "ip addr show eth0 " | Select-String '(?<=link/ether)\s[\w\:]+' | % Matches | % Value 

    echo "$id`t$mac`t$_"
}

# 判断一批编号是否存在

$txt = @"
19081FHHY000F3
1A181FDF6002FQ
"@

$dict = @{}
adb devices | ? {$_ -match '\bdevice\b'} | ? { -not ( $_ -like '*:*' ) }  | Select-String \w+ | % { $_.Matches.Value } | % {  $dict[$_.Trim()] = '1' } 

$txt.Split([char[]]"`r`n") | % {

    $devid = $_.Trim()
    if($devid){

        # echo "devid: $devid"
        # echo "dict: $dict[$devid]"

        if($dict[$devid]){
            Write-Host $devid # 存在正常输出
        }
        else{
            Write-Host $devid -ForegroundColor Red # 不存在,输出红字
        }
    }
}

 一些参考命令
 https://www.jianshu.com/p/76076df0df92

批量处理一批 ip 手机


1..80 | 
ForEach-Object { "10.10.107.$($_)" } | # 拼接 ip 
ForEach-Object { 
    $result = Test-Connection $_ -Count 1 -Quiet; # ping 地址 
    $msg = "$_ $result"
    if (-not $result) {
        Write-Host $msg -ForegroundColor Red # 失败仅输出
    }
    else {

        # 成功进行 adb 连接
        # Write-Host $msg -ForegroundColor Green
        # 拼接 adb 连接地址 
        $mobileAddress = "$($_):6667"
        adb connect $mobileAddress | Out-Null

        if ($?) {

            $wakeFunc = {

                # 唤醒屏幕
                $cmds = @()
                $cmds += "shell settings put global stay_on_while_plugged_in 3"
                $cmds += "shell settings put system screen_off_timeout 2147483647"
                $cmds += "shell svc power stayon true"
                $cmds += "shell locksettings set-disabled true"

                Write-Host $mobileAddress

                foreach($cmd in $cmds){                    
                    $command = "adb -s $mobileAddress $cmd"                     
                    Invoke-Expression $command
                }

                Write-Host ""
            }

            $idFunc = {
                # id 编号 
                $deviceId = adb -s $mobileAddress shell getprop ro.usedno
                $fakeId = adb -s $mobileAddress shell getprop ro.serialno

                Write-Host "$mobileAddress $deviceId $fakeId" 
            }

            $ipFunc = {
                # 调用 nc 获取外网 ip 
                adb -s $mobileAddress shell "echo -e 'GET / HTTP/1.1\r\nHost: ip.3322.net\r\nConnection: close\r\n\r\n' | nc ip.3322.net 80 " | Select-String "(\d+\.){3}\d+"  | % Matches | % Value
            }

            $cameraFun = {
                # 摄像头
                $info = adb -s $mobileAddress shell ' dumpsys media.camera | grep Facing '        
                $output = "$mobileAddress $info"            
                if ( -not (($info -like '*Back*' ) -and ($info -like '*Front*' )) ) {
                    Write-Host $output -ForegroundColor Red            
                } 
                else { 
                    echo $output 
                }
            }

            $dateFun = {
                # 检测系统时间
                $date = adb -s $mobileAddress shell ' date "+%Y-%m-%d %H:%M:%S %Z %z"'
                if ($date -notlike '*2025*') {
                    Write-Host "$mobileAddress $date" -ForegroundColor Red            
                }
                else {
                    Write-Host "$mobileAddress $date" 
                }

            }

            Invoke-Command $wakeFunc
        }

        # 断开 adb 连接, 生产机器上不要停止 
        # adb.exe disconnect $mobileAddress
    } 
}
上一篇
下一篇