Fix incorrect handling in multi-interface environment
[platform/upstream/connman.git] / test / get-proxy-autoconfig
1 #!/usr/bin/python
2
3 import dbus
4 import urllib.request, urllib.parse, urllib.error
5
6 def get_pac(url):
7         conn = urllib.request.urlopen(url, proxies={})
8         data = conn.read()
9         print(data)
10         conn.close()
11
12 bus = dbus.SystemBus()
13
14 manager = dbus.Interface(bus.get_object('net.connman', '/'),
15                                         'net.connman.Manager')
16
17 services = manager.GetServices()
18
19 for entry in services:
20         path = entry[0]
21         properties = entry[1]
22
23         proxy = properties["Proxy"]
24
25         if "Method" in proxy:
26                 print("[ %s ]" % (path))
27
28                 method = proxy["Method"]
29                 print("Method = %s" % (method))
30
31                 if method in ["auto"]:
32                         url = proxy["URL"]
33                         print("URL = %s" % (url))
34                         print()
35                         get_pac(url)
36                 else:
37                         print()