We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi I'm using the carnivore library/code to get some data of my network. I want to analyse and read as much packets as possible.
For the moment I'm troubled with the ascii convertion and saving the output of the console log.
I've used the createWriter() to log the console to a file. This only stops after hitting a key.
How could I turn this into a daily or maybe hourly 'save to file' happening. So I have multiple files with shorter amounts of code in it?
Answers
Nothing?
I think you could do something like this:
If I understood your question correct this should do it.
Ok I thought this was going to be easier ^^
Umh I followed the createWriter and joined your lines adapted to what I want to ouput.
No file is created when I start the sketch?
Here's the complete small code
Update!!! I get a file every hour but it's empt...
@Layzfat you made a typo in your code at line 21 you use
ouput = createWriter(date + ".txt");
instead ofoutput = createWriter(date + ".txt");
.I've never used printWriter but I think your files are empty because at line 29 you use
println
, Shouldn't it beoutput.println
?Hi, my bad copied the wrong sketch. The output was there. I removed the println because of this error before trying to 'compile'.
The global variable "println" does not exist .
Though the example doesn't make a variable of the println.. and I even don't think that's even possible/allowed..
@Lazyfat could you post the whole code? Since the code you posted before with my improvments runs just fine, altough Carnivore doesn't detect a network card so It creates empty logs
@schotsl I did gave you the full code, you have to download the carnivore library in the library import menu. Otherwise it doesn't work.
@Lazyfat I've downloaded the carnivore library, Try this code (I think you made a type somewhere)
Cause this works for me
Hi, I've copied and it's running, how did you test if the output files is generated with text. (change the clock?)
You can just replace every
hour()
withminute()
then it will save every minute so you just have to wait a minute. Although changing your clock would also probably work.What? I have copied the same code and added these two lines, just println?
And it doesn't work, empty files.
Could this be that I run it on a raspberry pi? I'll try on my laptop tomorrow to double check it.
@layzfat once again replace every
println
withoutput.println
soprintln("---------------------------\n");
would beccomeoutput.println("---------------------------\n");
@schotsl I think there is more at hand, because when I change all println to output.println I get this error. I went over the code multiple times and don't see anything missing or no typo.
ERROR java.lang.reflect.InvocationTargetException at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.rsg.carnivore.CarnivoreP5.newCarnivorePacket(CarnivoreP5.java:91) at org.rsg.carnivore.Core.dispatch(Core.java:230) at org.rsg.carnivore.PacketCacheThread.run(PacketCacheThread.java:37) Caused by: java.lang.NullPointerException at sketch_171213a.packetEvent(sketch_171213a.java:46) ... 6 more
COMPLETE CODE
I tested it on the raspberry pi and on my mac os. The codes run without the output.println but hangs when I add it.
be careful with this - windows doesn't like : in filenames.
i would also stick with just YYDDMMHH format because that way the files sort more sensibly. java's SimpleDateFormat is probably better than using hour() etc because hour() doesn't pad single digit hours and that will also cause confusion. (you can use nf() though)
https://forum.processing.org/two/search?Search=SimpleDateFormat
Kf
@koogs, care to show an example? :) Or is this a library? I'm not at home, will respond tonight if I found more and get it to work.
https://Forum.Processing.org/two/discussion/10067/how-to-prevent-file-overwriting#Item_3
Were you running this on a Raspberry-pi? Make sure you do your testing in a laptop. When it is working there, then you can switch to another platform. However, I am not sure if carnivore will work in your raspberry-pi... No experience in that department.
Notice in your post in Dec 13, you are creating your writer in draw(). That is a no no, like in don't do this in draw(). Instead, move these two lines to setup():
Also, you close your writer handle in a controlled manner meaning after a specific defined action. An example is illustrated in the reference: https://processing.org/reference/createWriter_.html so yes, do not close your output handle 30 times per second as you are doing right now.
After you have your sketch working in your laptop, then you can start thinking in migrating to raspberry-pi. This will call for creating another post to target that question (in my opinion).
Kf