用python开启临时http服务器及其ipv6支持

1,044次阅读
没有评论

python可以只用一行代码创建简单的http服务器,用来把linux的vps中文件拖回本地非常方便
高校的同学也可以用这个方法,通过ipv6给同学分享文件

pyhton3

python -m http.server
之后会看到输出Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) …

pyhton2

python -m SimpleHTTPServer
之后会看到输出Serving HTTP on 0.0.0.0 port 8000 …
之后在浏览器地址栏输入 ip地址:端口 即可访问

但是问题来了,无论py2还是py3,默认都不支持ipv6

为了解决ipv6支持的问题,2、3的方法还是略有区别

python3

python3安装目录/lib/http/server.py 的如下位置添加带有加号的两行
就是把
server_address = (bind, port) HandlerClass.protocol_version = protocol
改成
server_address = (bind, port) if ':' in bind: ServerClass.address_family = socket.AF_INET6 HandlerClass.protocol_version = protocol
然后代码
python -m http.server -b [::]
之后会看到输出Serving HTTP on :: port 8000 (http://:::8000/) …

python2

不用修改文件,直接一行代码
python -c "import socket,SocketServer,CGIHTTPServer;SocketServer.TCPServer.address_family=socket.AF_INET6;CGIHTTPServer.test()" 8080
之后会看到输出Serving HTTP on :: port 8080 …
实际上py2的这一行代码,是有如下三行的脚本文件生成的,python调用这个脚本,8080为其参数,是端口

import socket,SocketServer,CGIHTTPServer
SocketServer.TCPServer.address_family=socket.AF_INET6
CGIHTTPServer.test()

注意

1.浏览器访问ipv6地址需要加方括号
[ipv6地址]:端口

2.文件分享的路径就是命令行当前工作目录

3.代码运行在操作系统命令行,不是python命令行,例如win的cmd或者powershell,linux的bash命令行等

正文完
可以使用微信扫码关注公众号(ID:xzluomor)
post-qrcode
 0
评论(没有评论)

文心AIGC

2024 年 4 月
1234567
891011121314
15161718192021
22232425262728
2930  
文心AIGC
文心AIGC
人工智能ChatGPT,AIGC指利用人工智能技术来生成内容,其中包括文字、语音、代码、图像、视频、机器人动作等等。被认为是继PGC、UGC之后的新型内容创作方式。AIGC作为元宇宙的新方向,近几年迭代速度呈现指数级爆发,谷歌、Meta、百度等平台型巨头持续布局
文章搜索
热门文章
清库存!DeepSeek突然补全R1技术报告,训练路径首次详细公开

清库存!DeepSeek突然补全R1技术报告,训练路径首次详细公开

清库存!DeepSeek突然补全R1技术报告,训练路径首次详细公开 Jay 2026-01-08 20:18:...
训具身模型遇到的很多问题,在数据采集时就已经注定了丨鹿明联席CTO丁琰分享

训具身模型遇到的很多问题,在数据采集时就已经注定了丨鹿明联席CTO丁琰分享

训具身模型遇到的很多问题,在数据采集时就已经注定了丨鹿明联席CTO丁琰分享 衡宇 2026-01-08 20:...
手把手教你用AI 10分钟生成一个APP!零基础也能搞定

手把手教你用AI 10分钟生成一个APP!零基础也能搞定

今日,我将向大家展示DeepSeek的全新玩法——从零开始,利用AI创建一个完整的应用程序。借助DeepSee...
开源“裸考”真实世界,国产具身智能基座模型拿下全球第二!

开源“裸考”真实世界,国产具身智能基座模型拿下全球第二!

开源“裸考”真实世界,国产具身智能基座模型拿下全球第二! 西风 2026-01-08 19:02:20 来源:...
最新评论
ufabet ufabet มีเกมให้เลือกเล่นมากมาย: เกมเดิมพันหลากหลาย ครบทุกค่ายดัง
tornado crypto mixer tornado crypto mixer Discover the power of privacy with TornadoCash! Learn how this decentralized mixer ensures your transactions remain confidential.
ดูบอลสด ดูบอลสด Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
ดูบอลสด ดูบอลสด Pretty! This has been a really wonderful post. Many thanks for providing these details.
ดูบอลสด ดูบอลสด Pretty! This has been a really wonderful post. Many thanks for providing these details.
ดูบอลสด ดูบอลสด Hi there to all, for the reason that I am genuinely keen of reading this website’s post to be updated on a regular basis. It carries pleasant stuff.
Obrazy Sztuka Nowoczesna Obrazy Sztuka Nowoczesna Thank you for this wonderful contribution to the topic. Your ability to explain complex ideas simply is admirable.
ufabet ufabet Hi there to all, for the reason that I am genuinely keen of reading this website’s post to be updated on a regular basis. It carries pleasant stuff.
ufabet ufabet You’re so awesome! I don’t believe I have read a single thing like that before. So great to find someone with some original thoughts on this topic. Really.. thank you for starting this up. This website is something that is needed on the internet, someone with a little originality!
ufabet ufabet Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
热评文章
8块钱跑通一次强化学习全流程,潞晨云重塑微调赛道:1名算法工程师=1支Infra团队

8块钱跑通一次强化学习全流程,潞晨云重塑微调赛道:1名算法工程师=1支Infra团队

8块钱跑通一次强化学习全流程,潞晨云重塑微调赛道:1名算法工程师=1支Infra团队 思邈 2026-01-0...
手把手教你用AI 10分钟生成一个APP!零基础也能搞定

手把手教你用AI 10分钟生成一个APP!零基础也能搞定

今日,我将向大家展示DeepSeek的全新玩法——从零开始,利用AI创建一个完整的应用程序。借助DeepSee...
清库存!DeepSeek突然补全R1技术报告,训练路径首次详细公开

清库存!DeepSeek突然补全R1技术报告,训练路径首次详细公开

清库存!DeepSeek突然补全R1技术报告,训练路径首次详细公开 Jay 2026-01-08 20:18:...
训具身模型遇到的很多问题,在数据采集时就已经注定了丨鹿明联席CTO丁琰分享

训具身模型遇到的很多问题,在数据采集时就已经注定了丨鹿明联席CTO丁琰分享

训具身模型遇到的很多问题,在数据采集时就已经注定了丨鹿明联席CTO丁琰分享 衡宇 2026-01-08 20:...