概述
在创建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所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复