Score:1

Netdiscover output into a file

cg flag

I am trying to put the output of netdiscover into a file, I have been trying a lot of things, some examples:

sudo netdiscover -i eth0 > netwokdiscovery.txt
timeout 4s $(sudo netdiscover -i eth0)
echo -n "$(sudo netdiscover -i eth0)" > netwokdiscovery.txt
dd if=$(sudo netdiscover -i eth0) of=netwokdiscovery.txt

The only issue is I have all the output of netdiscover.

I want to run netdiscover for 2 minutes and put the last output into a file. Do you know if that is possible?

Artur Meinild avatar
vn flag
Wouldn't that "just" be to trim the file to the X last lines?
Score:1
jp flag

Not so good news

Redirecting the output of an interactive screen like that will usually result in a file that contains escape sequences ... These are control character sequences that you don't see and used for e.g. resetting/clearing the terminal screen or changing the position of the cursor ... etc.

Running the file command on the saved file should output something like this:

$ file file.txt
file.txt: ASCII text, with escape sequences

This kind of files/output can not be easily parsed/processed so cannot e.g. be easily separated to records/blocks so you get only the last block ... Sometimes it cannot even be displayed correctly in the terminal with e.g. cat file.txt as the escape sequences will alter the terminal's display.

Your best bet is to use the -P or -L switches(to produce an output suitable to be redirected into a file) as described in man netdiscover ... But, then you will lose the repeated screen headers and only one header is printed at the top of the file ... So, you can't e.g. process the text into blocks based on the header ... Sure, you can then e.g. combine the output of both head to print the first N lines and tail to print the last N lines like for examble:

{ head -n 3 file.txt; tail -n 12 file.txt; }

But, there will be no standard for e.g. how many lines to tail and not loose any important output.

So good news

My other answer in this post: Warn when new WiFi devices on LAN network has a bash script(The terminal display version) that will do what you want and without even the need for sudo ... It will both print in the terminal screen and to a log file ... It is also easily customizable if you know your bash.

ilie alexandru avatar
cg flag
Thank you so much @Raffa , I will try this as well. I end up doing it with awk and nmap due to the time constrains
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.