最简单的内网导航网站

栏目: Python · 发布时间: 6年前

内容简介:随着业务系统的增长,运维工具的增多,我们经常需要访问监控页面、ssh登录机器,需要记住很多常用信息,但是这些信息不值得占用宝贵的大脑资源,只需要存储下来用的时候访问即可。我们需要一个超简单的导航网站。如何最简单地实现一个静态的网站?不要任何多余的东西。

随着业务系统的增长,运维 工具 的增多,我们经常需要访问监控页面、ssh登录机器,需要记住很多常用信息,但是这些信息不值得占用宝贵的大脑资源,只需要存储下来用的时候访问即可。

我们需要一个超简单的导航网站。

最简单的静态网站实现

如何最简单地实现一个静态的网站?不要任何多余的东西。

最好几行代码实现服务,向外提供一个html文件访问服务。新增内容时候,只需要添加到html文件即可。

这时候就要介绍一下 python 3的HTTP server。

在控制台执行:

python -m http.server

就可以看到 Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) … ,python启动了一个http server端口默认是8000。访问 loalhost:8000 可以看到当前目录的文件列表。

我们就通过pyhton 的http server 来实现这个最简单的内网导航。

小项目就叫my123吧,项目只有2个文件,server.py和index.html。

服务代码 server.py 很简单:

#coding=utf-8

from http.server import HTTPServer, BaseHTTPRequestHandler
from os import curdir, sep

class MyRequestHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        if self.path=="/index.html" or self.path=='/':
                file = open(curdir+sep +'index.html')
                self.send_response(200)
                self.send_header('Content-Type', 'text/html;charset=utf-8')
                self.end_headers()
                self.wfile.write(bytes(file.read(),'utf-8'))
                file.close()

server = HTTPServer(('0.0.0.0', 8123), MyRequestHandler)
server.serve_forever()

主要逻辑就有访问 /index.html 或者 / 的时候,读取当前目录下的index.html文件,将内容返回。

index.html文件的内容:

<html>

<head>
      <meta charset="UTF-8">
        <title>常用网址导航</title>
</head>

<body>

<h2>监控</h2>

 <a href="http://your.server.name.com" target="view_window">A服务监控</a>  
 </br>

 <a href="http://your.server2.name.com" target="view_window">B服务监控</a>
</br>

...

</br></br></br></br>

</body>
</html>

就是简单的html内容,连CSS都没有。简单粗暴。

调用命令启动:

python server.py

搞定。


以上所述就是小编给大家介绍的《最简单的内网导航网站》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Beginning iPhone and iPad Web Apps

Beginning iPhone and iPad Web Apps

Chris Apers、Daniel Paterson / Apress / 2010-12-15 / USD 39.99

It seems that everyone and her sister has developed an iPhone App—everyone except you, the hard-working web professional. And now with the introduction of the iPad, you may even feel farther behind. B......一起来看看 《Beginning iPhone and iPad Web Apps》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具