1 | 1 | | import argparse |
2 | 2 | | import logging |
| 3 | + | import netifaces |
3 | 4 | | import os |
4 | 5 | | import tempfile |
5 | 6 | | import subprocess |
| skipped 38 lines |
44 | 45 | | """ |
45 | 46 | | Initializes the HTTP server. |
46 | 47 | | """ |
| 48 | + | interface = args.get("interface") |
| 49 | + | bind_cmd = [] |
| 50 | + | if interface: |
| 51 | + | bind_addr = netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['addr'] |
| 52 | + | bind_cmd = ["--bind", bind_addr] |
| 53 | + | |
47 | 54 | | # Create a temporary directory to run out of so we're not hosting files |
48 | 55 | | self.tmp_dir = tempfile.TemporaryDirectory() |
49 | 56 | | |
| skipped 5 lines |
55 | 62 | | stdout, stderr = None, None |
56 | 63 | | |
57 | 64 | | # Start the server |
| 65 | + | cmd = ["python3", "-m", "http.server", str(args.get('port'))] |
| 66 | + | cmd += bind_cmd |
58 | 67 | | try: |
59 | | - | subprocess.check_call(["python3", "-m", "http.server", str(args.get('port'))], stderr=stderr, stdout=stdout, cwd=self.tmp_dir.name) |
| 68 | + | subprocess.check_call(cmd, stderr=stderr, stdout=stdout, cwd=self.tmp_dir.name) |
60 | 69 | | except subprocess.CalledProcessError as exc: |
61 | 70 | | logger.debug("Server exited: %s", str(exc)) |
62 | 71 | | |
| skipped 8 lines |