查找nginx 配置文件中有效的域名
2017-04-27 00:00
381 查看
摘要: 在日常工作中。配置文件很多。查找域名很费事,用grep 查找出来很混乱没有排序。有的域名查找出来也没有使用,也可能到期之类的情况。催生了这个程序出来。
#!/usr/bin/env python ##重庆话语科技---运维部--莲花子 ##python/shell ##群号:35666534 欢迎你 import multiprocessing import re,string,sys,urllib2,urllib,json,time,operator,optparse,os,fnmatch import socket menu=optparse.OptionParser() menu.add_option("-l","--leixin",help="nginx config type") menu.add_option("-s","--source",help="single source nginx config") menu.add_option("-p","--path",help="source nginx config path") opt,argv=menu.parse_args() def check_s_r(file=None): BUF_SIZE = 1024 domain=[] out=[] server_name="NO" bigfile = open(file,'r') tmp_lines = bigfile.readlines(BUF_SIZE) while tmp_lines: for line in tmp_lines: if re.findall(r'(?<=server_name)\s+(.*);',line): server_name=re.findall(r'(?<=server_name)\s+(.*);',line)[0] for name in re.split(r'(\s+)',server_name): if name.strip(): domain.append(name.strip()) return domain tmp_lines = bigfile.readlines(BUF_SIZE) def chkping(url): try: ip=socket.gethostbyname(url) if not ip in ['0.0.0.0','127.0.0.1','10.0.0.1']: return(url,True) else: return (url,False) except: return (url,False) def find(_path=None,_type=None): fuck={} pool = multiprocessing.Pool(processes = 7) for root, dirs, files in os.walk(_path): for f in files: if fnmatch.fnmatch(f,_type): try: domain=check_s_r(os.path.join(root,f)) for idomain in domain: if not fuck.has_key(f): fuck.update({idomain:f}) except: pass s=pool.imap(chkping,fuck) for i in s: if i[1] == False: fuck.pop(i[0]) pool.close() pool.join() sorted_x=sorted(fuck.iteritems(), key=lambda p:(p[0].split(".")[-2:5],p[0]),reverse=False ) for i in sorted_x: print "{0:-<30}\t{1:_>1}".format(i[0],i[1]); def check_cmd(): if opt.path != None and opt.leixin !=None: find(opt.path,opt.leixin) elif opt.source != None : check_s_r(opt.source) check_cmd()
相关文章推荐
- nginx配置用户认证、域名跳转、日志记录、静态文件缓存、防盗链
- Nginx 配置域名 .conf 文件
- nginx配置虚拟域名后直接输出或下载网页源代码而不是运行网页文件的解决办法
- Nginx 查找配置文件路径
- Linux下如何查找nginx配置文件的位置
- nginx多域名代理配置文件模版(
- LAMP架构(nginx安装,默认虚拟主机,用户认证,域名重定向,nginx配置文件详解)
- Nginx (安装+ 配置域名+ 访问认证 +发布文件)
- Nginx(二)配置文件及域名虚拟主机
- nginx配置域名、设置文件上传大小
- linux下如何查找nginx配置文件的位置
- 【Nginx】nginx通过端口/域名区分主机配置文件
- LNMP架构 (2)之 Nginx安装、默认虚拟主机、用户认证、域名重定向、配置文件详解
- nginx安装路径,查找配置文件以及如何配置
- nginx 安装ssl证书及域名配置文件
- Nginx 一个服务器多域名配置 以及 访问php文件直接下载而不运行
- nginx 多域名配置,采用多配置文件的方式GOOD
- nginx 配置多域名,配置多个conf 文件
- 用Perl写一个读取nginx配置文件到csv,实现域名与IP对应的实用程序
- 查找配置文件,并返回文件的绝对路径