My OS sistem is Windows 10.
I use android x86 in my emulator.
I used virtualbox as emulator machine and the network of virtualbox set to:
-Bridge Adapter (connection type)
-Intel(R) Dual Band Wireless-AC 3168 (Name)
-Intel PRO/1000 MT Desktop (8254OEM) -> (adapter type)
-Allow All (Promiscuous mode)
I set that because of that set is working to make my emulator connect to internet.
i use python to run a script that use the emulator.
the problem is when i use different network, the IP of the emulator is change..
so some part of my code is not working when i change the network that i use, the code is:
from subprocess import Popen, PIPE
import os
ip_emulator ='192.168.100.15' #the ip got from "ALT + F1" and type ipconfig on emulator
fileadb = 'adb.exe'
pathsys32 = r'C:\Users\admin\AppData\Local\Android\Sdk\platform-tools'
adb = os.path.join(pathsys32, fileadb)
cek = Popen([adb, 'connect', ip_emulator], stdout=PIPE, stderr=PIPE)
because of the ip change in emulator, caused by change my network that i used (eg, change from use network at home to office network or use mobile modem).
i should make a code to detect the emulator ip to make sure my adb is connected to emulator.
how to do that? to cek it outside the emulator by python, without get in to emulator (eg. press ALT + F1, and type ifconfig).
I already try use: "arp -a" but sometimes the ip show sometimes not.
already try "netstat -a" no emulator ip show there
the code to detect via arp:
from subprocess import Popen, PIPE
import os
import re
arpfile = 'ARP.EXE'
fileadb = 'adb.exe'
pathsys32 = r'C:\Windows\System32'
arp = os.path.join(pathsys32, arpfile)
adb = os.path.join(pathsys32, fileadb)
def detectiparp():
cek = Popen([arp, '-a'], stdout=PIPE, stderr=PIPE)
out, err = cek.communicate()
outdata = (out.decode('utf-8')).split('\n')
for i in outdata:
mac = '08-00-27-ce-9e-8c'
rexmac = re.search(mac, i)
if rexmac:
ipre = '([0-9]{0,}\.[0-9]{0,}\.[0-9]{0,}\.[0-9]{0,})\s.+?08-00-27-ce-9e-8c'
iprex = re.search(ipre, i)
ip_emu = iprex.group(1)
return ip_emu
else:
return False
ip_emulator = detectiparp()
cek = Popen([adb, 'connect', ip_emulator], stdout=PIPE, stderr=PIPE)
I already read:
How to get the Android Emulator's IP address?
How to get the IP address of an emulator to communicate to the local server
and i think all of the answer is "cek your emulator IP from inside the emulator" or "use the default set of IP (10.0.2.2)"
so, i explaining something, IP 10.0.2.2 only happens if the connection type that i use in virtualbox is NAT type, but with that setting, my emulator cannot connect to internet.
Already try use:
1st network set as NAT and 2nd Network set as Bridge, but the IP change to C class (192.169.x.x), and the emulator's ip still change if i use different network.
if i know how to detect my emulator IP (from host/ laptop / outside my emulator), i can make the code, or there is python module that i can use to detect it?