Skip to content

Instantly share code, notes, and snippets.

@hvisser
Created July 11, 2014 12:22
Show Gist options
  • Save hvisser/5da0e0666d3ef2861e46 to your computer and use it in GitHub Desktop.
Save hvisser/5da0e0666d3ef2861e46 to your computer and use it in GitHub Desktop.
Monkey runner script to set the proxy on Android from the "modify network" screen.
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
import sys
import socket
import time
device = MonkeyRunner.waitForConnection()
host = socket.gethostbyname(socket.gethostname())
port = "8888"
if len(sys.argv) >= 2:
host = sys.argv[1]
if len(sys.argv) >= 3:
port = sys.argv[2]
device.wake()
device.press("KEYCODE_DPAD_DOWN")
device.press("KEYCODE_DPAD_DOWN")
device.press("KEYCODE_ENTER")
time.sleep(1)
device.press("KEYCODE_DPAD_DOWN")
device.press("KEYCODE_ENTER")
time.sleep(1)
device.press("KEYCODE_DPAD_DOWN")
device.press("KEYCODE_ENTER")
time.sleep(1)
# ICS appears to need this extra "down"
# device.press("KEYCODE_DPAD_DOWN")
# time.sleep(1)
device.press("KEYCODE_DPAD_DOWN")
time.sleep(1)
print "host"
device.type(host)
time.sleep(1)
device.press("KEYCODE_DPAD_DOWN")
time.sleep(1)
device.type(port)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment