osx - Parse Output of Command into Variable LIVE (Network Traffic Monitoring) -
i writing network monitoring script in bash. base command using ettercap -t -m arp -i en1 // //
. pipe egrep --color 'host:|get'
it.
a sample output getting looks this:
get /images/srpr/logo11w.png http/1.1. host: www.google.com. /en-us/us/products http/1.1. host: www.caselogic.com.
my desired output this:
title: logo11w.png url: www.google.com/images/srpr/logo11w.png http/1.1. title: products - case logic url: www.caselogic.com/en-us/us/products
things notice: http/1.1.
, .
@ end of host gone. formed 1 url
, there blank line after each title
/url
listing. attempted forming them 1 url parsing commands output variable with
var=`sudo ettercap -t -m arp -i en1 // // | egrep --color 'host:|get'` | echo $var
but doesn't work because input variable command isn't done until user requests stop (ctrl + c
).
to title of html page, use command wget -qo- 'https://url.goes/here' | perl -l -0777 -ne 'print $1 if /<title.*?>\s*(.*?)\s*<\/title/si'
. if doesn't have title, such image, no title fine.
any appreciated, , sorry if wrote hard read, feel free ask questions.
try this:
title_host.pl
#!/usr/bin/env perl use warnings; use strict; use www::mechanize; $mech = www::mechanize->new(); ($get,$host,$title); while (<>) { if (m|^get (\s+) |) { $get = $1; } elsif ( m|^host: (\s+)\.| ) { $host = $1; } else { # unrecognized line...reset $get = $host = $title = ''; } if ($get , $host) { ($title) = $get =~ m|^.*\/(.+?)$|; # default title $url = 'http://' . $host . $get; $mech->get($url); if ($mech->success) { # html may have title, images not $title = $mech->title() || $title; } print "title: $title\n"; print "url: $url\n"; print "\n"; $get = $host = $title = ''; } }
input
get /images/srpr/logo11w.png http/1.1. host: www.google.com. /en-us/us/products http/1.1. host: www.caselogic.com.
now pipe input perl script:
cat input | perl title_host.pl
output:
title: logo11w.png url: http://www.google.com/images/srpr/logo11w.png title: products - case logic url: https://www.caselogic.com/en-us/us/products
Comments
Post a Comment