Parse Output of Command into Variable LIVE (Network Traffic Monitoring)

前端 未结 1 1904
暖寄归人
暖寄归人 2021-01-14 13:24

I am writing a network monitoring script in bash. The base command I am using is ettercap -T -M ARP -i en1 // //. Then I pipe egrep --color \'Host:|GET\'<

相关标签:
1条回答
  • 2021-01-14 14:04

    Try this:

    title_host.pl

    #!/usr/bin/env perl
    
    use warnings;
    use strict;
    use WWW::Mechanize;
    
    my $mech = WWW::Mechanize->new();
    
    my ($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 and $host) {
            my ($title) = $get =~ m|^.*\/(.+?)$|; # default title
            my $url = 'http://' . $host . $get;
            $mech->get($url);
            if ($mech->success) {
                # HTML may have title, images will 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.
    GET /en-us/us/products HTTP/1.1.
    Host: www.caselogic.com.
    

    now just pipe your input into the 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
    
    0 讨论(0)
提交回复
热议问题