Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 680587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:23:22+00:00 2026-05-14T01:23:22+00:00

The goal is to mine packet headers for URLs visited using tcpdump. So far,

  • 0

The goal is to mine packet headers for URLs visited using tcpdump.

So far, I can save a packet header to a file using:

tcpdump "dst port 80 and tcp[13] & 0x08 = 8" -A -s 300 | tee -a ./Desktop/packets.txt

And I’ve written a program to parse through the header and extract the URL when given the following command:

cat ~/Desktop/packets.txt | ./packet-parser.exe

But what I want to be able to do is pipe tcpdump directly into my program, which will then log the data:

tcpdump "dst port 80 and tcp[13] & 0x08 = 8" -A -s 300 | ./packet-parser.exe

Here is the script as it is. The question is: how do I need to change it to support continuous input from tcpdump?

#include <boost/regex.hpp>
#include <fstream>
#include <cstdio> // Needed to define ios::app
#include <string>
#include <iostream>

int main()
{
    // Make sure to open the file in append mode
    std::ofstream file_out("/var/local/GreeenLogger/url.log", std::ios::app);
    if (not file_out)
        std::perror("/var/local/GreeenLogger/url.log");
    else
    {
        std::string text;
        // Get multiple lines of input -- raw
        std::getline(std::cin, text, '\0');
        const boost::regex pattern("GET (\\S+) HTTP.*?[\\r\\n]+Host: (\\S+)");
        boost::smatch match_object;
        bool match = boost::regex_search(text, match_object, pattern);
        if(match)
        {
            std::string output;
            output = match_object[2] + match_object[1];
            file_out << output << '\n';
            std::cout << output << std::endl;
        }
        file_out.close();
    } 
}

Thank you ahead of time for the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:23:22+00:00Added an answer on May 14, 2026 at 1:23 am

    You’re going to have to make some bigger changes to get it to work. Your getline delimited by ‘\0’ won’t terminate until it either sees a ‘\0’ (which isn’t going to happen) or the input reaches EOF. That’s why it works when you use a file (which eventually reaches EOF) but not with streaming straight from tcpdump.

    I’m having trouble compiling with Boost, so I’m still not totally sure this will work. But you should get the idea. [Edit: It works :-)]

     std::string text, line1, line2;
    
     std::getline(std::cin, line1);
     while(std::getline(std::cin, line2)) {
       text = line1 + '\n' + line2;
       // ...
       line1 = line2;
     }
     file_out.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Goal : I wants when I drag image it become fade so we can
My ultimate goal is to have a dry base repository that I can override
Goal : Update an existing host header for an IIS7.5 site with powershell Problem
Goal is to replace 'byebye' with 'Hello ' # START: file.txt contains string byebye
A friend of mine really likes using Joomla as a base for his websites.
Goal: Create Photomosaics programmatically using .NET and C#. Main reason I'd like to do
Goal: write a query that can bring back all the users of a company,
Goal is to make a dialog that appears on menu_key pressed, but it keeps
Goal: Once i click on the start button on my user interface, i currently
Goal: Produce an Excel document with information from 3 associated models that is similar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.