Hello,
I'm trying to create a program who'll catch the mac address connections. For
this, I take the /var/log/arpalert.log and create a dict. with the results in
JSON. I'm a beginner in Python.
For now, I have the arpalert log to a file.txt. I take this file and create a
dictionary in an other file. I transform the result to JSON format. But the
problem is the "format" of my dictionary. In the Json format I have all the
informations of one connection in a key, and all the informations of another
connection in the value of the key.
But what I want is a key "mac" with the address in value, a key "ip" with the
address in value, etc...
This is my code for now :
from json import dumps, dump
from itertools import izip
def get_log(source, destination):
log = open(source, 'r')
fil_dest = open(destination, 'w')
txt = log.readline()
while txt:
fil_dest.write(txt)
txt = log.readline()
log.close()
fil_dest.close()
def to_json(source, destination):
fil_dest = open(destination, 'w')
with open(source, 'r') as lines:
txt = lines.readlines()
wanted_lines = txt[0:]
i = iter(wanted_lines)
dict_log = dict(izip(i, i))
dump(dict_log, fil_dest, sort_keys=True, indent=1)
lines.close()
fil_dest.close()
get_log('/var/log/arpalert.log', 'arpalert_strings.txt')
to_json('arpalert_strings.txt', 'json_conversion.txt')
and the result in JSON ("key": "value")
"Oct 8 14:45:52 arpalert: seq=2, mac=a2:e5:68:3c:16:f1, ip=192.168.1.19,
type=new, dev=p3p1, vendor=\"(null)\"\n": "Oct 8 14:45:52 arpalert: seq=3,
mac=04:e8:ca:a8:6f:b8, ip=192.168.1.19, type=new, dev=p3p1,
vendor=\"(null)\"\n",
"Oct 9 09:41:46 arpalert: Auto selected device: bluetooth0\n": "Oct 9
09:41:46 arpalert: [./capture.c 181] ioctl[19] : No such device\n",
Anybody can help me please ? I tried with regex but I'm lost and I losing my
mind !
--
https://mail.python.org/mailman/listinfo/python-list