#!/usr/bin/env python3
'''
Server files from current directory.
Requirements: Python3.4+
'''importsocketimportargparseimporthttp.serverimportsocketserverparser=argparse.ArgumentParser(description='Serve files from the current \
directory.')host_name=socket.gethostname()ip=socket.gethostbyname(host_name)parser.add_argument('--host',default=ip,type=str,required=False,help='Specify the ip address to listen on.')parser.add_argument('--port',default=8080,type=int,required=False,help='Specify the port to listen on.')args=parser.parse_args()handler=http.server.SimpleHTTPRequestHandlerwithsocketserver.TCPServer((args.host,args.port),handler)ashttpd:print(f'Server is listening on {args.host} on port {args.port}.')httpd.serve_forever()
Hey Chinmay,
I turned this idea into a small program. It gets the IP address automatically. Run it like this
$ python3 server_files.py
OR like this
$ python3 server_files.py --host '192.168.12.34' --port 1234
github.com/brandon-wallace/serve_f...