有这么一段内容如下,我需要把IP和对应的MAC分别的抓取出来,我不知道该如何入手了。
刘辉 192.168.1.2 E8:9A:8F:8E:7E:C2
陈瑾 192.168.1.3 1C:6F:65:61:81:1F
卢万敏 192.168.1.5 88:AE:1D3:71:32
徐莹 192.168.1.4 00:1A:4D:34:12:9E
>>> import re
>>> with open('a') as f:
... for line in f:
... aList = re.findall('\S+',line)
... print aList[1],aList[2]
...
192.168.1.2 E8:9A:8F:8E:7E:C2
192.168.1.3 1C:6F:65:61:81:1F
192.168.1.5 88:AE:1D:32:71:32
192.168.1.4 00:1A:4D:34:12:9E
#! /usr/bin/python
#encoding=utf-8
import re
srcfile="in.txt"
patterm = re.compile("^\[.*?\]\s+?at")
patterm2 =re.compile("Exception")
try:
f=open(srcfile)
fout = open("out.txt","w")
except:
raise IOError('..')
lines = [line for line in f.readlines()]
for line in lines:
content = patterm.search(line)
if content is not None:
fout.write(line)
content = patterm2.search(line)
if content is not None:
fout.write(line)
f.close()
fout.close()
阅读(1197) | 评论(0) | 转发(0) |