Last active
January 14, 2020 15:22
-
-
Save colesbury/df218a96334dbd31ee0e93760f70f114 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/data/users/sgross/python3/bin/python3 | |
import http.server | |
import socket | |
import sys | |
import argparse | |
parser = argparse.ArgumentParser(description='Serve the current directory') | |
parser.add_argument('--port', '-p', type=int, default=8095) | |
class HTTPServerV6(http.server.HTTPServer): | |
address_family = socket.AF_INET6 | |
def main(): | |
args = parser.parse_args() | |
port = args.port | |
server = HTTPServerV6(('::', port), http.server.SimpleHTTPRequestHandler) | |
hostname = socket.gethostname() | |
result = socket.getaddrinfo(hostname, port, socket.AF_INET6) | |
ipv6 = result[0][4][0] | |
sys.stderr.write('http://[{}]:{}\n'.format(ipv6, port)) | |
server.serve_forever() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment