Miki Tebeka avatar Miki Tebeka committed de92755

host to bind

Comments (0)

Files changed (1)

 '''
 
 __author__ = 'Miki Tebeka <miki.tebeka@gmail.com>'
-__version__ = '0.2.0'
+__version__ = '0.3.0'
 
 from contextlib import contextmanager
 from six import b, exec_, string_types
 EOF = chr(4)
 DEFAULT_PORT = 9998
 
+
 @contextmanager
 def redirect_stdout(fo):
     old_stdout = sys.stdout
                 error = format_exc()
                 self.wfile.write(b(error))
 
-
     def finish(self):
         try:
             socksrv.StreamRequestHandler.finish(self)
     allow_reuse_address = True
 
 
-def server_thread(env, port, password=None, redirect=False):
+def server_thread(env, port, password=None, redirect=False, host='localhost'):
     # Create a new handler class for this with it's own env
     class Handler(PyHandler):
         pass
     Handler.password = password
     Handler.redirect = redirect
 
-    server = ThreadedServer(('localhost', port), Handler)
+    server = ThreadedServer((host, port), Handler)
     server.serve_forever()
 
 
-def install(env=None, port=DEFAULT_PORT, password=None, redirect=False):
+def install(env=None, port=DEFAULT_PORT, password=None, redirect=False,
+            host='localhost'):
     env = env or {}
-    t = Thread(target=server_thread, args=(env, port, password, redirect))
+    t = Thread(target=server_thread,
+               args=(env, port, password, redirect, host))
     t.daemon = True
     t.start()
 
                         default=None)
     parser.add_argument('-r', '--redirect', help='redirect stdout',
                         default=False, action='store_true')
+    parser.add_argument('-s', '--host', help='host to bind to',
+                        default='localhost')
     args = parser.parse_args(argv[1:])
 
-    t = install(port=args.port, password=args.login, redirect=args.redirect)
-    print('Serving on port {0}'.format(args.port))
+    t = install(port=args.port, password=args.login, redirect=args.redirect,
+                host=args.host)
+    print('Serving on {0}:{1}'.format(args.host, args.port))
     t.join()
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.