- """
- import web
- urls = (
- '/(.*)', 'hello'
- )
- app = web.application(urls, globals())
- class hello:
- def GET(self, name):
- if not name:
- name = 'World'
- return 'Hello, ' + name + '!'
- if __name__ == "__main__":
- app.run()
- """
- """
- @cmd_on_web_03.py
- @cs200522@163.com
- @2013-07-31 17:00
- @
- 1.用python2.7在xp系统中实现,客户端在网页中点击相应的链接,
- 客户端执行诸如ipconfig、ping、netstat等cmd命令。这样用户就不需要在输入相关的cmd命令,
- 而是只需要打开网页,点击相关的链接;
- 2.因为目前所维护的机器上,并不是所有的机器都给安装远程控制软件的;
- 3.想使用B/S模式,这样我在服务器上也能看到相关的输出,省下电话沟通的一些信息了。
- 4.目前只是实现了命令在网页上显示出来,还没有做出超链接或者用户输入提交请求,然后输出结果......
- 5.目前只是参考web.py的hello改写的。存在的问题有:
- A、在IE6.0 、IE8.0中显示无换行,不规整;
- B、firefox中无法显示汉字,虽然代码设置了utf-8,但是firefox显示的汉字还是乱码,除非手工改动firefox编码为gbk
- 上诉两个问题还没有找到解决办法.....
- """
- #!/usr/bin/env python
- #coding=utf-8
- import web
- import os
- import sys
- import subprocess
- reload(sys)
- sys.setdefaultencoding('utf-8')
- urls = (
- '/(.*)', 'hello'
- )
- app = web.application(urls, globals())
- class hello:
- def GET(self,name):
- #if not name:
- #name= 'world'
- #f=os.popen("cmd.exe /C dir")
- #f=os.popen("cmd.exe /C dir")
- p = subprocess.Popen("ipconfig",shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
- output, error = p.communicate()
- return output
- #return f.readlines()
- if __name__ == "__main__":
- app.run()
- #该片段来自于http://www.codesnippet.cn/detail/291020136762.html
来源: http://www.codesnippet.cn/detail/291020136762.html