我是靠谱客的博主 秀丽云朵,这篇文章主要介绍python httpserver 支持ipv6,现在分享给大家,希望可以做个参考。

在创建HTTPServer实例之前将address_family设置成socket.AF_INET6

#!/usr/bin/python
import commands
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
import socket,SocketServer

PORT_NUMBER = 8080

class myHandler(BaseHTTPRequestHandler):

    #Handler for the GET requests

    def do_GET(self):

        print 'get method'

        return

try:
    #Create a web server and define the handler to manage the
    #incoming request

    cmd = "ip addr|grep 'scope global'|grep inet6|awk -F' ' '{print $2}'|awk -F'/' '{print $1}'"
    (status,ipv6) = commands.getstatusoutput(cmd)

    if ipv6 != "" :
        SocketServer.TCPServer.address_family=socket.AF_INET6

    server = HTTPServer(('', PORT_NUMBER), myHandler)
    print 'Started httpserver on port ' , PORT_NUMBER

    #Wait forever for incoming htto requests
    server.serve_forever()

except KeyboardInterrupt:
    print '^C received, shutting down the web server'
    server.socket.close()

 

最后

以上就是秀丽云朵最近收集整理的关于python httpserver 支持ipv6的全部内容,更多相关python内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部