设为首页 加入收藏

TOP

Python 用socket模块实现检测端口和检测web服务(二)
2014-11-24 03:17:14 来源: 作者: 【 】 浏览:5
Tags:Python socket 模块 实现 检测 web 服务
check = check_webserver(options.address, options.port, options.resource)


print 'check_webserver returned %s' % check


sys.exit(not check)


运行结果:


正常


[root@centos python]# python check_web.py -a 192.168.137.2 -p 80 -r index.html


options: {'resource': 'index.html', 'port': 80, 'address': '192.168.137.2'}, args: []


HTTP request:


|||GET /index.html HTTP/1.1


Host: 192.168.137.2


|||


Attempting to connect to 192.168.137.2 on port 80


Connected to 192.168.137.2 on port 80


Received 100 bytes of HTTP response


|||HTTP/1.1 200 OK


Date: Wed, 19 Jun 2013 02:29:31 GMT


Server: Apache/2.2.3 (CentOS)


Last-Modified: |||


Closing the connection


First line of HTTP response: HTTP/1.1 200 OK


Version: HTTP/1.1, Stuats: 200, Message: OK


Success - status was 200


check_webserver returned True


不正常,找不到页面的情况


[root@centos python]# python check_web.py -a 192.168.137.2 -p 80 -r ppp.html


options: {'resource': 'ppp.html', 'port': 80, 'address': '192.168.137.2'}, args: []


HTTP request:


|||GET /ppp.html HTTP/1.1


Host: 192.168.137.2


|||


Attempting to connect to 192.168.137.2 on port 80


Connected to 192.168.137.2 on port 80


Received 100 bytes of HTTP response


|||HTTP/1.1 404 Not Found


Date: Wed, 19 Jun 2013 02:29:41 GMT


Server: Apache/2.2.3 (CentOS)


Content-|||


Closing the connection


First line of HTTP response: HTTP/1.1 404 Not Found


Version: HTTP/1.1, Stuats: 404, Message: Not Found


Staus was 404


check_webserver returned False


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Python 重定向shell执行输出 下一篇Python 发送email

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·常用meta整理 | 菜鸟 (2025-12-25 01:21:52)
·SQL HAVING 子句:深 (2025-12-25 01:21:47)
·SQL CREATE INDEX 语 (2025-12-25 01:21:45)
·Shell 传递参数 (2025-12-25 00:50:45)
·Linux echo 命令 - (2025-12-25 00:50:43)