我是靠谱客的博主 秀丽云朵,最近开发中收集的这篇文章主要介绍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 httpserver 支持ipv6所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部