I’m writing a node.js application where I need to do a lot of parsing of stdout for various commands into javascript objects that I can send to the browser over a websocket connection.
Lets use ping as an example. I want to send back the stdout
64 bytes from ip.isp.com (123.123.123.123): icmp_seq=2 ttl=53 time=7.92 ms
as an object like
{
'icmp_seq': 2,
'ttl': 53,
'time': '7.92 ms'
}
There are a number of different commands I want to do this too, including nmap, so I want to make sure I’m doing it as efficiently and intelligently as possible. My plan right now is to just do splits and regex matches but I want to make sure I’m not missing something.
Try this regular expression:
Run this with the multi-line option. You will have to tweak it to work with all output you may receive but for the line you posted it will work.
Once you have the result you can pull each match out into its own variable or into a JSON object.