30

So I have set up charles proxy to monitor traffic that goes out of the android emulator.

Now when I open a website it in the Android browser For eg:- google.com I see google.com in charles proxy.

But when I open an app(say instagram app) in the emulator and if the app makes some network calls , I see ip addresses on charles proxy and not domain names.

Because of which the app gives me an error of something went wrong etc.

Can anyone tell me how to change the dns configs of the android emulator so that it sends hostnames instead of IP addresses?

Or any other solution to this problem.

Thanks

azero0
  • 2,220
  • 3
  • 20
  • 31
  • Is your android emulator running on linux or windows? It looks at /etc/resolv.conf on linux, you can also use -dns-server xx.xx.xx.xx on the command line to set it manually. Does it output any warning message that it can't find a DNS server? Are sure the packets with IP addresses are coming from the apps like Instagram or whatever? – ozborn Dec 29 '15 at 19:56
  • 1
    @ozborn I am using mac. I am sure the packets are coming from instagram and I have also tried setting up other dns servers(8.8.8.8) without any success. Do you by chance know how the networking exactly work in android emulator? Because when I try to access sites from the android browser I am able to see hostnames on charles proxy monitoring .But when I use apps ip addresses come up. – azero0 Dec 30 '15 at 04:43
  • I know how DNS and networking work, but haven't messed with the android emulator in a while. I'm not sure DNS is even the issue or that you would expect to see DNS traffic with your charles proxy, if your networking is configured correctly and you get back reasonable router addresses from your DNS server your app should work. If you do "nslookup google.com 10.0.2.3" on your emulator console what do you get? – ozborn Dec 30 '15 at 17:34

6 Answers6

1

you can configure a proxy from the command line with the -http-proxy option when starting the emulator. In this case, you specify proxy information in in one of these formats:

http://<machineName>:<port>

or

http://<username>:<password>@<machineName>:<port>

The -http-proxy option forces the emulator to use the specified HTTP/HTTPS proxy for all outgoing TCP connections. Redirection for UDP is not currently supported.

Alternatively, you can define the environment variable http_proxy to the value you want to use for . In this case, you do not need to specify a value for in the -http-proxy command — the emulator checks the value of the http_proxy environment variable at startup and uses its value automatically, if defined.

You can use the -debug-proxy option to diagnose proxy connection problems.

You can get further detail about this topic here:

https://developer.android.com/studio/run/emulator-networking.html
0

There's no way to change the dns configs of the android emulator that can get hostnames instead of IP addresses, the only option to use proxy is explain on other SO threads here.

I am sure the packets are coming from instagram and/or maybe they use some firewall for security purpose.

Community
  • 1
  • 1
0

It is not possible with emulator but you can use GENYMOTION for that. Genymotion is very good tool to use online emulator.

enter image description here

You can set proxy in setting->network.

enter image description here

try that .hope this will help you.

KDeogharkar
  • 10,939
  • 7
  • 51
  • 95
  • I know it works with genymotion I wanted to make it work with the regular android emulator.. – azero0 Jan 04 '16 at 08:59
0

For Linux User

We can't able to use emulator started from android studio We have to start emulator from terminal using this 2 commands

First Move to android sdk tools dir

$ cd /home/..../Android/Sdk/tools

Second start your emulator using this cmd

./emulator -avd Emulator_name -http-proxy http://Ur ip address:port/

Emulator_name : open AVD Manager second column you will get Emulator names, next you have to replace spaces in between name with underscore

like Nexus 5 API 22 --> Nexus_5_API_22

Eg: $ ./emulator -avd Nexus_5_API_22 -http-proxy http://12.1.0.222:8888/

Community
  • 1
  • 1
ramji
  • 1,982
  • 2
  • 13
  • 13
0

Inside your emulator - go to settings ->network&internet ->mobileNetwork ->AccessPointNames. and then choose your network for editing it and put the IP and port of the Charles's computer.

Remember to open the emulator with poxy. emulator with proxy

soosita
  • 187
  • 13
-2

You can use 'ping' command to get the IP address.

Mr.Wu
  • 1
  • 1