Android之经过adb shell 模拟器 error: more than one device and emulator 改ip dns

error: more than one device and emulatorjava

若是出现上面那种状况 请关闭  ide linux

输入下面的  再次从新启动 模拟器android

若是实际上只有一个设备或模拟器,而且查到有offline的状态;
那就说明是ADB自己的BUG所致使的,就须要用以下的方法处理下了:
C:\Users\gaojs>adb kill-server
C:\Users\gaojs>taskkill /f /im adb.exe
第一条命令是杀ADB的服务,第二条命令是杀ADB的进程!
若是第一条没有用,才考虑用第二条命令再试试看的!git

 

adb connect 192.168.2.103:5555   ip地址 模拟器查看方法  下载一个wifi adb 给root权限 就能看到
adb devices  再次输入 能看到有 上面ip列表github

 

 

 

当我连着手机充电的时候,启动模拟器调试,执行ADB指令时,报错。
C:\Users\gaojs>adb shell
error: more than one device and emulator
C:\Users\gaojs>adb install e:\good.apk
error: more than one device and emulatorshell

碰到这种状况,首先要查一下,是否是真的有多个设备或模拟器。
C:\Users\gaojs>adb devices
List of devices attached
emulator-5554   device
4dfadcb86b00cf05        device
发现还真是多个设备,那就须要为ADB命令指定设备的序列号了。
C:\Users\gaojs>adb -s emulator-5554 shell
也就是如上所示,给命令加上-s的参数就能够了!ubuntu

若是实际上只有一个设备或模拟器,而且查到有offline的状态;
那就说明是ADB自己的BUG所致使的,就须要用以下的方法处理下了:
C:\Users\gaojs>adb kill-server
C:\Users\gaojs>taskkill /f /im adb.exe
第一条命令是杀ADB的服务,第二条命令是杀ADB的进程!
若是第一条没有用,才考虑用第二条命令再试试看的!缓存

---------------------
做者:杭州山不高
来源:CSDN
原文:https://blog.csdn.net/gaojinshan/article/details/9455193
版权声明:本文为博主原创文章,转载请附上博文连接!服务器

 

经过shell命令设置(获取)IP、网关、dns信息,须要获取root权限markdown

查看全部网络信息

  1.  
    C:\>adb shell
  2.  
    root@android :/ # netcfg
  3.  
    netcfg
  4.  
    ip6tnl 0 DOWN 0.0.0.0/0 0x00000080 00:00:00:
  5.  
    00:00:00
  6.  
    gre 0 DOWN 0.0.0.0/0 0x00000080 00:00:00:
  7.  
    00:00:00
  8.  
    eth 0 UP 192.168.0.180/24 0x00001043 00:00:00:
  9.  
    ec:0a:00
  10.  
    sit 0 DOWN 0.0.0.0/0 0x00000080 00:00:00:
  11.  
    00:00:00
  12.  
    lo UP 127.0.0.1/8 0x00000049 00:00:00:
  13.  
    00:00:00
  14.  
    tunl 0 DOWN 0.0.0.0/0 0x00000080 00:00:00:
  15.  
    00:00:00

查看eth0

  1.  
    root@android :/ # ifconfig eth0
  2.  
    ifconfig eth 0
  3.  
    eth0: ip 192.168.0.180 mask 255.255.255.0 flags [up broadcast running multicast]

查看dns

  1.  
    root@android :/ # getprop net.eth0.dns1
  2.  
    getprop net.eth 0.dns1
  3.  
    8.8.8.8
  4.  
     
  5.  
    root@android :/ # getprop net.eth0.dns2
  6.  
    getprop net.eth 0.dns2
  7.  
    8.8.4.4

设置ip

  1.  
    root@android :/ # ifconfig eth0 192.168.0.173 netmask 255.255.255.0
  2.  
    ifconfig eth 0 192.168.0.173 netmask 255.255.255.0
  3.  
     
  4.  
    root@android :/ # ifconfig eth0
  5.  
    ifconfig eth 0
  6.  
    eth0: ip 192.168.0.173 mask 255.255.255.0 flags [up broadcast running multicast]

设置网关Gateway

  1.  
    root@android:/ # route add default gw 192.168.0.1 dev eth0
  2.  
    route add default gw 192.168.0.1 dev eth0

添加dns

  1.  
    root@android :/ # setprop net.eth0.dns1 8.8.8.8
  2.  
    setprop net.eth 0.dns1 8.8.8.8
  3.  
     
  4.  
    root@android :/ # setprop net.eth0.dns2 8.8.4.4
  5.  
    setprop net.eth 0.dns2 8.8.4.4

查看eth配置信息

  1.  
    root@android:/ # getprop | grep eth0
  2.  
    getprop | grep eth0
  3.  
    [ dhcp.eth0.dns1]: [192.168.0.1]
  4.  
    [ dhcp.eth0.dns2]: []
  5.  
    [ dhcp.eth0.dns3]: []
  6.  
    [ dhcp.eth0.dns4]: []
  7.  
    [ dhcp.eth0.gateway]: [192.168.0.1]
  8.  
    [ dhcp.eth0.ipaddress]: [192.168.0.180]
  9.  
    [ dhcp.eth0.leasetime]: [3600]
  10.  
    [ dhcp.eth0.mask]: [255.255.255.0]
  11.  
    [ dhcp.eth0.pid]: [13800]
  12.  
    [ dhcp.eth0.reason]: [PREINIT]
  13.  
    [ dhcp.eth0.result]: [failed]
  14.  
    [ dhcp.eth0.server]: [192.168.0.1]
  15.  
    [ dhcp.eth0.vendorInfo]: []
  16.  
    [ net.change]: [net.eth0.dns2]
  17.  
    [ net.eth0.dns1]: [8.8.8.8]
  18.  
    [ net.eth0.dns2]: [8.8.4.4]
  19.  

 

        3)、getprop | grep dns 过滤dns

                   

           4) 、getprop | grep dns 输出dns

                 

             5) 、修改dns  须要root ,而后输入 adb shell 而后输入su命令 而后set dhcp.wlan0.dns1 8.8.8.8

 

二、查看手机ip

             输入netstat

            

 

Android通常是经过设置界面来配置各类网络信息,今天讲一下当不方便使用设置的时候,经过shell命令来查看和配置网络的方法。
注:如下shell命令在不一样版本Android系统上可能存在差别。

查看网络链接信息
查看所有链接
#netcfg
ccmni2 DOWN 0.0.0.0/0 0x00000080 11:22:22:33:44:11
ccmni0 DOWN 0.0.0.0/0 0x00000080 2a:3d:e1:22:5d:11
ccmni1 DOWN 0.0.0.0/0 0x00000080 1e:bc:dd:5a:32:11
wlan0 UP 192.168.1.151/24 0x00001043 5c:f7:c3:dd:44:11
tunl0 DOWN 0.0.0.0/0 0x00000080 00:00:00:00:00:00
lo UP 127.0.0.1/8 0x00000049 00:00:00:00:00:00
sit0 DOWN 0.0.0.0/0 0x00000080 00:00:00:00:00:00
p2p0 UP 0.0.0.0/0 0x00001003 5e:f7:c3:dd:44:11
ifb0 DOWN 0.0.0.0/0 0x00000082 e6:a9:76:38:04:11
ifb1 DOWN 0.0.0.0/0 0x00000082 96:d6:f4:59:10:11
ip6tnl0 DOWN 0.0.0.0/0 0x00000080 00:00:00:00:00:11
1
2
3
4
5
6
7
8
9
10
11
12
查看指定链接
#ifconfig wlan0
wlan0: ip 192.168.1.151 mask 255.255.255.0 flags [up broadcast running multicast]
1
2
设置IP
方法1:
//ifconfig <dev> <ip> netmask <value>
例:ifconfig wlan0 192.168.1.10 netmask 255.255.255.0
1
2
方法2:
//ip address add <ip> dev <value>
例:ip address add 192.168.1.10/24 dev wlan0
1
2
设置默认网关
设置默认网关主要是经过路由表

ip route add 192.168.1.0/24 via 192.168.1.1
1
也能够直接使用dhcp命令来自动获取

netcfg wlan0 dhcp
1
设置DNS
设置dns的方法比较多,可是不一样环境,以及不一样的系统版本,能生效的方式不必定相同,能够多试几种,这里提供一种我用的方式,适用于Android 5.1,其余系统参照https://github.com/ukanth/afwall/wiki/DNS#resolver-commands

ndc resolver setnetdns <netid> <domain> <dns1> <dns2>
例:ndc resolver setnetdns wlan0 "" 8.8.8.8 8.8.4.4
1
2
以前在xda论坛上看到过其余方式,若是以上方式无效,也能够看一下这个论坛里的方法https://forum.xda-developers.com/general/xda-university/guide-how-to-change-dns-android-device-t3273769

这些命令有的比较简单,用法也比较单一,好比netcfg,可是有的就要复杂一些,好比路由表的配置。Android 的shell环境里没有man的命令,查看具体的命令用法通常就是在命令后加-h 或者help。

参考:
DNS-commands
ifconfig vs ip
[GUIDE] How to Change DNS in Android Device (8 methods)
---------------------
做者:feiniao8651
来源:CSDN
原文:https://blog.csdn.net/feiniao8651/article/details/81664039
版权声明:本文为博主原创文章,转载请附上博文连接!

 

 

android 4.1系统上,经过usb以太网进行上网,发现udhcpc获取到ip和dns,而且ip设置到网络节点成功,dns server也配置到/etc/resolv.conf文件中成功,但老是ping IP正常,而ping domain失败:unkown host.
最后,有同事发现原来android上的dns配置与linux上有所不一样,android上还须要经过设置属性net.dns1,net.dns2,setprop后便可正常工做了。。。

附参考:http://blog.163.com/my_ywj/blog/static/1812035592011730104753938/

经过ubuntu等Linux系统都是经过resolve.conf文件进行域名解析的,经过man resolve.conf能够查看到:

 

The  resolver is a set of routines in the C library that provide access to the Internet Domain Name System (DNS).  The  resolver  configuration file  contains  information  that  is read by the resolver routines the first time they are invoked by a process.  The file is designed  to  be human readable and contains a list of keywords with values that provide various types of resolver information. If this file doesn't exist the only name server to be queried  will  be       on  the  local machine; the domain name is determined from the hostname and the domain search path is constructed from the domain name.

 

因此DNS解析是由C库函数进行解析的,在Android中bionic/libc/docs/overview.txt文件中咱们也能够看到:

NS resolver:
  Bionic uses a NetBSD-derived resolver library which has been modified in the following ways:
     - don't implement the name-server-switch feature (a.k.a. <nsswitch.h>)
     - read /system/etc/resolv.conf instead of /etc/resolv.conf
     - read the list of servers from system properties. the code looks for 'net.dns1', 'net.dns2', etc.. Each property should contain the IP address of a DNS server.
       these properties are set/modified by other parts of the Android system (e.g. the dhcpd daemon).
       the implementation also supports per-process DNS server list, using the properties 'net.dns1.<pid>', 'net.dns2.<pid>', etc... Where <pid> stands for the numerical ID of the current process.
     - when performing a query, use a properly randomized Query ID (instead of a incremented one), for increased security.
     - when performing a query, bind the local client socket to a random port for increased security.
     - get rid of *many* unfortunate thread-safety issues in the original code
  Bionic does *not* expose implementation details of its DNS resolver; the content of <arpa/nameser.h> is intentionally blank. The resolver implementation might change completely in the future.

因此android关注的是resolv.conf以及net.dns1等属性。

 

通 过adb shell中经过getprop查看属性,确实有net.dns一、net.dns2以及wifi中的net.tiwlan0.dns1以及 net.tiwlan0.dns2,移动网络中的net.rmnet0.dns1以及net.rmnet0.dns2等属性。

 

转自 [(http://blog.csdn.net/ganyue803/article/details/51646284)]

1、android中代码 
framework端,设置dns服务器代码路径以下: 
kk-4.x/libcore/luni/src/main/java/java/net/InetAddress.java 
kk-4.x/frameworks/base/services/java/com/android/server/NetworkManagementService.java 
kk-4.x/frameworks/base/services/java/com/android/server/NativeDaemonConnector.java 
NetworkManagementService中函数setDnsServersForInterface 
最终会经过本地socket传输命令到守护进程netd 
因此framework层还可使用INetworkManagementService mNetd 来更改dns地址

2、和dns相关libc代码路径以下: 
kk-4.x/bionic/libc/netbsd

3、netd模块,netd是一个守护进程 
kk-4.x/system/netd

4、其余命令设置dns 
iptables -t nat -A OUTPUT -p udp –dport 53 -j DNAT –to-destination 202.96.134.33:53

取消设置的DNS: 
iptables -t nat -L OUTPUT -n -v –line-numbers 
iptables -t nat -D OUTPUT linenumber

5、第一次开机起来后获取DNS:

/data/data/com.android.providers.settings/databases/Settings.db 里面有保存dns数据

在开机状态下,获取DNS: 
EthernetManager能够设置获取DNS,这个dns是保存在内存的键值对中。

6、流程 
android 4.3以后经过DNS获取ip,采用netd代理,netd是一个守护进程。

经过ndc命令能够配置DNS服务器: 
ndc resolver setifdns eth0 “” 8.8.8.8 8.8.4.4 
各个版本支持的ndc命令: 
https://github.com/bparmentier/DNSSetter/wiki/ndc-resolver-commands

一、ndc经过本地socket将命令传给netd 
二、经过netd调用res_cache将dns1和dns2等信息保存到cache中 
三、 netd调用bionic libc下netbsd中函数getaddrinfo 
四、libc更新要访问的dns服务器ip地址

android中请求DNS服务器,获取ip流程以下

上层应用设置dns

NativeDaemonConnector经过java本地socket,将命令 
发送给NetD

若是不走netd,流程以下:

注:lbc为android下bionic里面的libc

若是4.3以后有需求,须要和4.3以前同样,经过属性配置DNS。 
那么能够合并4.0.3代码,即res_init.c中合并经过属性获取DNS 
服务器ip地址代码,经过在本身的程序中设置环境变量: 
setenv(“ANDROID_DNS_MODE”, “local”, 1);不要export。

固然不合并代码也是能够的,只须要修改dns服务器地址。 
在res_init中res_setservers里面能够修改

struct addrinfo hints, *ai; 
memset(&hints, 0, sizeof(hints)); 
hints.ai_family = PF_UNSPEC; 
hints.ai_socktype = SOCK_DGRAM; 
hints.ai_flags = AI_NUMERICHOST; 
sprintf(sbuf, “%u”, NAMESERVER_PORT); 
sprintf(propname, “net.dns%d”, i+1); 
__system_property_get(propname,propvalue); 
printf(” propname: %s \n”,propname); 
printf(“propvalue dns: %s \n”,propvalue); 
char* p = propvalue; 
while (*p == ’ ’ || *p == ‘\t’) 
p++; 
p[strcspn(p, “;# \t\n”)] = ‘\0’; 
if (getaddrinfo(propvalue, sbuf, &hints, &ai) != 0){ 
memcpy(&statp->nsaddr_list[nserv],&set->sin, size); 
}else{ 
memcpy(&statp->nsaddr_list[nserv],ai->ai_addr, ai->ai_addrlen); 
}

若是不修改底层代码,是能够经过ndc命令修改DNS服务器的。原理就是第一个图。

基本请求流程以下:

android apk上从dns服务器获取ip方式以下:

new Thread( networkTask).start();

Runnable networkTask = new Runnable() { 
@Override 
public void run() { 
try { 
InetAddress inetAddress = InetAddress.getByName( “www.baidu.com”); 
Log. i( TAG, “Address is getHostName:” + inetAddress.getHostName()); 
Log. i( TAG, “Address is ” + inetAddress.getHostAddress()); 
} catch (Exception e) { 
e.printStackTrace(); 
Log. i( TAG, “Address is Exception”); 


};

< uses-permission android:name = “android.permission.INTERNET” />

 

 

shell命令

文件操做相关命令
  1. cd : 进入文件目录内 至关于咱们双击某个文件夹 进入内部
  2. cat: 查看文件的内容,好比 .txt文件中的文本;
    -b -n -s:显示行号,-b会忽略空行,-s连续空行记为一行
  3. df: 列出分区列表 好比 系统分区,sdcard分区等
  4. du: 查看文件或者目录的磁盘使用空间
  5. ls: 列出目录内容
    -a: 列出全部文件,包括隐藏文件
    -i: 输出文件的i节点的索引信息
    -l: 列出文件的详细信息
    -n: 用数字的GUID代替名称
    -s: 输出文件的大小
  6. grep: 指定文件中搜索特定内容,并将含有这些内容的行标准输出
  7. mkdir: 建立目录,-p,--parents:递归建立目录
  8. touch: 建立文件 语法:touch [-alm] [-t XXXX[.YYY]] <file>
  9. rm: 删除文件 语法:rm[-f|-i] [-dPRrvWx] file
    -f: 强制删除文件,系统不提示
    -i: 交互式删除,删除前有提示
    -d: 改变硬连接数据删成0,删除该文件
    -r,-R: 递归删除全部子目录下的文件和目录
  10. rmdir: 删除目录,-p: 递归删除目录,只能删除空目录
  11. mv: 移动文件 语法:mv [-fiv] directory
    -f: 强制移动,若已经存在目标则直接覆盖
    -i: 若目标文件已经存在,会询问是否覆盖
  12. dd: 复制文件 语法:dd if=source of=target
  13. chmod: 文件权限修改 语法:chmod[OPTION]<MODE><FILE>
    -R: 递归的改变文件和目录
    -h: 不遵循符号链接
  14. chown: 更改某个文件或者目录的属主或属组 语法:chown [-R[-H|-L|-P]] [-fhv] owner:group|owner|:group file
  15. md5: 查询文件的md5值 语法:md5 file
  16. mount: 挂载设备信息 语法:mount [-r] [-w] [-o options] [-t type] device directory
  17. remount: 从新挂载设备,能够改变可访问权限 语法: mount -o remount,[rw/ro/..权限] [设备名] [文件路径]
  18. umount: 卸载分区挂载 语法:umount <path>
  19. cmp: 要指出两个文件是否存在差别 语法:cmp [-b] [-l] [-n count] file1 file2
  20. ln: 用来在文件之间建立链接 语法:ln [-fhinsv] [-s] file1 file2
    有[-s]是软链接(链接文件不会复制一份被链接文件的内容)
    没有为硬链接
信息查询相关命令
  1. dumpstate: 系统状态信息 包括手机当前的内存信息、CPU信息、logcat缓存、kernel缓存等等
//-e : 表示虚拟机 //path : 将信息打印到path路径文件下 adb -e shell dumpstate > path 
  1. bugreport: 里边包含dmesg、dumpstate和dumpsys
//-e : 表示虚拟机 //path : 将信息打印到path路径文件下 adb -e shell bugreport> path 
  1. dmesg: kernel(内核)的log
//-d : 表示USB外接设备 adb -d shell dmesg 
  1. logcat: 打印日志缓冲区日志
//-d : 表示USB外接设备 adb -d shell logcat 
  1. dumpsys: 获取系统各项服务信息
//-d : 表示USB外接设备 //meminfo: 内存信息 adb -d shell dumpsys meminfo //cpuinfo: cpu信息 adb -d shell dumpsys cpuinfo //activity: activity信息 //find "mF": 过滤当前前台activity adb -d shell dumpsys activity | find "mF" 
  1. getevent: 获取按键信息
//-d : 表示USB外接设备 adb -d shell getevent 
  1. getprop: 获取系统属性
//-d : 表示USB外接设备 adb -d shell getprop 
  1. setprop: 设置系统属性(须要root权限)
  2. pm: 安装包管理,查询安装包的各类信息 pm还包含不少其余指令 好比安装 卸载等等
//-d : 表示USB外接设备 adb -d shell pm //列举全部的安装包 adb -d shell pm list packages 
  1. ps: 查看进程信息
//-d : 表示USB外接设备 adb -d shell ps 
  1. top: 获取CPU使用状况
//显示全部cpu使用状况并每隔几秒更新一次 adb -d shell top //-m: 最大显示条数 //-n: 更新次数 //-d: 更新时间间隔几秒 //-s: 排序依据(cpu vss rss thr) //-t: 显示线程信息而不是进程 //-h: 显示帮助文档 adb -d shell top -m 10 -n 10 -d 2 -s rss -t -h 
  1. procrank: 查看各进程内存消耗状况(须要root权限)
//-d : 表示USB外接设备 adb -d shell procrank 
做者:Cats_eat_fish 连接:https://www.jianshu.com/p/4386d14d2783 来源:简书 简书著做权归做者全部,任何形式的转载都请联系做者得到受权并注明出处。
相关文章
相关标签/搜索