当IP在10.x.x.x

时间:2017-03-24 09:28:34

标签: android networking android-emulator wireshark

我有一台在我的电脑上运行的网络服务器。我正在开发一个在AVD模拟器上测试的Android应用程序。模拟器使用IP地址10.0.2.2访问主机上的localhost。这样,一切都运作良好。

但是,我想要做的是在我的电脑上安装Wireshark,并在我的电脑上捕获Android应用和Web服务器之间的网络流量。

使用地址10.0.2.2时无法完成此操作,您需要使用Web服务器的IP。(Web服务器仅在本地,它没有公共IP)。

问题在于,在我们的网络中,所有PC都具有10.x.x.x范围内的本地地址。因此,当尝试连接到我的PC本地IP 10.a.b.c时,连接失败,因为仿真器也使用相同的地址空间。

解决这个问题最简单的方法是什么?

更改我的电脑本地IP不是一种选择。

编辑:我找到了一种更改仿真器正在使用的子网的方法。 我发现Android使用的是quemu。阅读this后,我使用以下命令从命令行启动了模拟器:

emulator @Nexus_5X_API_25 -qemu -netdev user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9

eumlator启动但我得到以下警告:警告: netdev mynet0没有对等

当我使用 adb shell 检查Android设备的IP时,我看到设备IP仍然是10.0.2.15,所以它仍然使用10.0.2.x地址空间,而不是192.168 .xx正如我所料。

我在quemu文档中找到了这个注释,但找不到需要添加到命令的其他参数:Note - if you specify any networking options on the command line (via -net or -netdev) then QEMU will require you to provide options sufficient to define and connect up both parts. (Forgetting to specify the backend or the network device will give a warning message such as "Warning: netdev mynet0 has no peer", "Warning: vlan 0 is not connected to host network" or "Warning: vlan 0 with no nics"; the VM will then boot but will not have functioning networking.)

EDIT2:我将命令更改为这样,现在没有警告:@Nexus_5X_API_25 -debug init -qemu -netdev user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9 -device virtio-net-pci,netdev=mynet0

然而,它仍然无法正常工作,因为emulator.exe无法覆盖qemu的netdev命令并将其追加到最后,因此网络设置保持不变。

以下是生成的QEMU选项列表:

emulator: argv[00] = "C:\Users\nikola\AppData\Local\Android\sdk\emulator/qemu/windows-x86_64/qemu-system-i386.exe"
emulator: argv[01] = "-dns-server"
emulator: argv[02] = "xx.xx.xx.xx,xx.xx.xx.xx,xx.xx.xx.xx,xx.xx.xx.xx"
emulator: argv[03] = "-serial"
emulator: argv[04] = "null"
emulator: argv[05] = "-cpu"
emulator: argv[06] = "android32"
emulator: argv[07] = "-enable-hax"
emulator: argv[08] = "-smp"
emulator: argv[09] = "cores=2"
emulator: argv[10] = "-m"
emulator: argv[11] = "1536"
emulator: argv[12] = "-lcd-density"
emulator: argv[13] = "420"
emulator: argv[14] = "-kernel"
emulator: argv[15] = "C:\Users\xxx\AppData\Local\Android\sdk/system-images\android-25\google_apis\x86\/kernel-ranchu"
emulator: argv[16] = "-initrd"
emulator: argv[17] = "C:\Users\xxx\AppData\Local\Android\sdk/system-images\android-25\google_apis\x86\/ramdisk.img"
emulator: argv[18] = "-object"
emulator: argv[19] = "iothread,id=disk-iothread"
emulator: argv[20] = "-drive"
emulator: argv[21] = "if=none,overlap-check=none,cache=unsafe,index=0,id=system,file=C:\Users\xxx\.android\avd\Nexus_5X_API_25.avd\system.img.qcow2,read-only"
emulator: argv[22] = "-device"
emulator: argv[23] = "virtio-blk-pci,drive=system,iothread=disk-iothread,modern-pio-notify"
emulator: argv[24] = "-drive"
emulator: argv[25] = "if=none,overlap-check=none,cache=unsafe,index=1,id=cache,file=C:\Users\nikola\.android\avd\Nexus_5X_API_25.avd/cache.img.qcow2,l2-cache-size=1048576"
emulator: argv[26] = "-device"
emulator: argv[27] = "virtio-blk-pci,drive=cache,iothread=disk-iothread,modern-pio-notify"
emulator: argv[28] = "-drive"
emulator: argv[29] = "if=none,overlap-check=none,cache=unsafe,index=2,id=userdata,file=C:\Users\xxx\.android\avd\Nexus_5X_API_25.avd/userdata-qemu.img.qcow2,l2-cache-size=1048576"
emulator: argv[30] = "-device"
emulator: argv[31] = "virtio-blk-pci,drive=userdata,iothread=disk-iothread,modern-pio-notify"
emulator: argv[32] = "-drive"
emulator: argv[33] = "if=none,overlap-check=none,cache=unsafe,index=3,id=sdcard,file=C:\Users\xxx\.android\avd\Nexus_5X_API_25.avd/sdcard.img.qcow2,l2-cache-size=1048576"
emulator: argv[34] = "-device"
emulator: argv[35] = "virtio-blk-pci,drive=sdcard,iothread=disk-iothread,modern-pio-notify"
emulator: argv[36] = "-netdev"
emulator: argv[37] = "user,id=mynet"
emulator: argv[38] = "-device"
emulator: argv[39] = "virtio-net-pci,netdev=mynet"
emulator: argv[40] = "-netdev"
emulator: argv[41] = "user,id=mynet2,net=10.0.3.0/24"
emulator: argv[42] = "-device"
emulator: argv[43] = "virtio-net-pci,netdev=mynet2"
emulator: argv[44] = "-show-cursor"
emulator: argv[45] = "-L"
emulator: argv[46] = "C:\Users\xxx\AppData\Local\Android\sdk\emulator/lib/pc-bios"
emulator: argv[47] = "-soundhw"
emulator: argv[48] = "hda"
emulator: argv[49] = "-vga"
emulator: argv[50] = "none"
emulator: argv[51] = "-netdev"
emulator: argv[52] = "user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9"
emulator: argv[53] = "-device"
emulator: argv[54] = "virtio-net-pci,netdev=mynet0"
emulator: argv[55] = "-append"
emulator: argv[56] = "qemu=1 androidboot.hardware=ranchu clocksource=pit android.qemud=1 console=0 console=0 android.checkjni=1 qemu.gles=1 ndns=4"
emulator: argv[57] = "-android-hw"
emulator: argv[58] = "C:\Users\xxx\.android\avd\Nexus_5X_API_25.avd/hardware-qemu.ini"

我用xxx替换了所有敏感数据

1 个答案:

答案 0 :(得分:0)

您可以使用redir工具使用类似的方法:

redir --laddr = 10.xx.xx.xx --lport = 5555 --caddr = 127.0.0.1 --cport = 5555 redir --laddr = 10.xx.xx.xx --lport = 5555 --caddr = 127.0.0.1 --cport = 5555 redir --laddr = 10.xx.xx.xx --lport = 5037 --caddr = 127.0.0.1 --cport = 5037