python 匹配关键字

  • Post author:
  • Post category:python


#!/usr/bin/env python

#-*-coding:utf8-*-

import os,sys,re

def read():

os.chdir(‘/etc/openvpn/sn10001/etc/’)

files = open(‘server.conf’,’r’).readlines()

b = [i.strip() for i in files]

for n in b:

if re.match(‘^server’,n):

vip = re.search(‘[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}’,n).group()

print vip

if __name__ == “__main__”:



read()



版权声明:本文为swq499809608原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。