37,720
社区成员
发帖
与我相关
我的任务
分享
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import os
DOMAIN_LIST = ['xx.com','www.xx.com','www.baidu.com','www.sina.com','www.si.com']
def func(domainlist):
for domain in domainlist:
if os.system(" ping {0} -n 1 -w 1".format(domain)):
logging.error('Host {} is unreachable!'.format(domain))
# 开启日志
LOG_PATH = r'd:/temp/ping.log'
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
filename=LOG_PATH,
filemode='a')
if __name__ == '__main__':
func(DOMAIN_LIST)
import os
e=['xx.com','www.xx.com','www.baidu.com','www.sina.com','www.si.com']
s=filter(lambda v:os.system(" ping {0} -n 1 -w 1".format(v)),e)
print(list(s))