Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78938
| X-Received | by 10.182.45.162 with SMTP id o2mr1234487obm.20.1412934568872; Fri, 10 Oct 2014 02:49:28 -0700 (PDT) |
|---|---|
| X-Received | by 10.140.92.110 with SMTP id a101mr269qge.23.1412934568765; Fri, 10 Oct 2014 02:49:28 -0700 (PDT) |
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!h18no4182012igc.0!news-out.google.com!i10ni76qaf.0!nntp.google.com!s7no1680961qap.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Fri, 10 Oct 2014 02:49:28 -0700 (PDT) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=80.15.17.183; posting-account=OTZV9QoAAAA3TlllkBoycWwfEiHEyeoF |
| NNTP-Posting-Host | 80.15.17.183 |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <6fe8f03d-e336-49ad-87ed-3e417f069afa@googlegroups.com> (permalink) |
| Subject | Results of arpalert to json in python |
| From | raphael houtin <raphael.houtin@gmail.com> |
| Injection-Date | Fri, 10 Oct 2014 09:49:28 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| Xref | csiph.com comp.lang.python:78938 |
Show key headers only | View raw
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 !
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Results of arpalert to json in python raphael houtin <raphael.houtin@gmail.com> - 2014-10-10 02:49 -0700
csiph-web