diff --git a/examples/mitmproxywrapper.py b/examples/mitmproxywrapper.py index 751332b7f..344cd53b8 100755 --- a/examples/mitmproxywrapper.py +++ b/examples/mitmproxywrapper.py @@ -11,6 +11,8 @@ import subprocess import re import argparse import contextlib +import os +import sys class Wrapper(object): @@ -103,6 +105,12 @@ class Wrapper(object): if self.proxy_enabled_for_service(service_name): self.disable_proxy_for_service(service_name) + @classmethod + def ensure_superuser(cls): + if os.getuid() != 0: + print 'Relaunching with sudo...' + os.execv('/usr/bin/sudo', ['/usr/bin/sudo'] + sys.argv) + @classmethod def main(cls): parser = argparse.ArgumentParser(description='Helper tool for OS X proxy configuration and mitmproxy') @@ -122,5 +130,6 @@ class Wrapper(object): if __name__ == '__main__': + Wrapper.ensure_superuser() Wrapper.main()