Skip to content

Instantly share code, notes, and snippets.

@nicola
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicola/63bb6868cfcd7bab81f6 to your computer and use it in GitHub Desktop.
Save nicola/63bb6868cfcd7bab81f6 to your computer and use it in GitHub Desktop.
Find open FirefoxOS connection open and listening for remote debugging
import psutil
def get_connections(p):
try:
return p.get_connections()
except:
return []
def is_listening(c):
return c.status == "LISTEN" and c.laddr[1] != 2828
def find_ports(p):
return [c.laddr[1] for c in get_connections(p) if is_listening(c)]
def discover_rdp_ports():
firefox = []
firefoxos = []
for p in psutil.process_iter():
name = p.name()
if name == 'b2g-bin' or name == 'b2g':
firefoxos = firefoxos + find_ports(p)
elif name == 'firefox' or name == 'firefox-bin':
firefox = firefox + find_ports(p)
return {'firefox': firefox, 'firefoxos': firefoxos}
if __name__ == '__main__':
print discover_rdp_ports()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment