This repository was archived by the owner on Nov 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp-share
More file actions
executable file
·57 lines (48 loc) · 1.29 KB
/
http-share
File metadata and controls
executable file
·57 lines (48 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import os
import psutil
import SimpleHTTPServer
import SocketServer
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument(
'--port',
'-p',
default='8080',
action='store'
)
parser.add_argument(
'--dir',
'-d',
default='',
action='store',
help='reltive path to share'
)
parser.add_argument(
'--interface',
'-i',
default='',
action='store',
help='set interface to listen on. Listen on all interfaces by default'
)
arguments = parser.parse_args()
return arguments
def get_iface_ips(port, interface):
if interface == '':
for iface, cfg in psutil.net_if_addrs().items():
print('http://{}:{}'.format(cfg[0].address, port))
else:
print('http://{}:{}'.format(interface, port))
def main(args):
share = os.path.join(os.getcwd(), args.dir)
os.chdir(share)
port = int(args.port)
handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer((args.interface, port), handler)
get_iface_ips(port, args.interface)
httpd.serve_forever()
if __name__ == '__main__':
args = parse_arguments()
main(args)