首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >python检测主机状态

python检测主机状态

作者头像
py3study
发布2020-01-10 11:07:38
发布2020-01-10 11:07:38
1.1K0
举报
文章被收录于专栏:python3python3
代码语言:javascript
复制
#!/usr/bin/python
import dns.resolver, os, httplib
iplist = []
appdomain = "cdsendmail.ecwise.com"
def checkip(ip):
checkurl = ip + ":80"
getcontent = ""
httplib.socket.setdefaulttimeout(5)
conn = httplib.HTTPConnection(checkurl)
代码语言:javascript
复制
    try:
            conn.request("GET","/",headers = {"host": appdomain})
            r = conn.getresponse()
            getcontent = r.read(15)
            print(getcontent)
    finally:
            if getcontent == "<!DOCTYPE html ":
                    print ip + " [OK]"
            else:
                    print ip + " [error]"
代码语言:javascript
复制
def getip(domain):
try:
a = dns.resolver.query(domain, 'A')
except Exception as E:
print "dns resolve error"+str(E)
return 0
for i in a.response.answer:
for j in i.items:
iplist.append(j.address)
print iplist
return True
if name == "main":
if getip(appdomain) and len(iplist) > 0:
for ip in iplist:
checkip(ip)
else:
print "dns resolve error!"
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/08/28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档