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 6760175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:02:10+00:00 2026-05-26T14:02:10+00:00

I am working on an app that monitors network usage. However I noticed many

  • 0

I am working on an app that monitors network usage. However I noticed many ways to do this does not allow exclusion of local traffic (say, Time Machine).

I am looking for a way to exclude local traffic, and only monitors usage that goes directly to/from the internet.

Update: Thank you for your replies, now I know how to find if the traffic is local, but I still don’t know how I can calculate total in/out bytes (sorry if I didn’t elaborate earlier). I have no way of knowing how many bytes are sent/received locally (or to the internet) in a certain period of time, or since the OS starts. This problem is further complicated by the fact processes are launched or killed when the OS is running.

The answer to the question How to get network adapter stats in linux/Mac OSX? gives an interesting way of summing up total usage but it doesn’t help because the usage it sums up are interface statistics.

Update 2: I’ve posted my final solution to this. Please scroll down a bit to see.

  • 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-26T14:02:10+00:00Added an answer on May 26, 2026 at 2:02 pm

    The final working solution I have is to use libpcap to achieve this. Of course there are some downsides, which includes it requires elevated privileges and must capture all filtered packets to calculate statistics, but at least it works perfectly well.

    Many documentations and tutorials on libpcap is fairly thorough and clear, I suggest every one interested in this solution to look at those with relatively little google-fu effort.

    Also it may interest a few that my filter for internet traffic is simply the following –

    - (NSString *)_internetFilterStringForInterface:(AKNetworkInterface *)interface
        inOrOut:(BOOL)inYesOutNo
    {
        if (![interface net] || ![interface mask] || IsEmpty([interface addresses]))
        {
            return nil;
        }
    
        NSString *hostType = inYesOutNo ? @"dst" : @"src";
        NSString *host = nil;
        for (NSString *hostComponent in [interface addresses])
        {
            if (IsEmpty(hostComponent)) continue;
            if (!host)
                host = [NSString stringWithFormat:@"(%@ host %@", hostType, hostComponent];
            else
                host = [host stringByAppendingFormat:@" or %@ host %@", hostType, hostComponent];
        }
        host = [host stringByAppendingString:@")"];
    
        NSString *net = [interface netString];
        net = [net stringByReplacingOccurrencesOfString:@".0" withString:@""];
    
        NSString *filter = [NSString stringWithFormat:
                            @"ip and (not %@ net %@) and %@",
                            inYesOutNo ? @"src" : @"dst",
                            net, host];
        return filter;
    }
    

    The filter is designed with some of the answers about what counts as ‘local traffic’, I know it does not encompass some edge cases such as double NAT configurations, etc., but I would like to see suggestions about this.

    I know net = [net stringByReplacingOccurrencesOfString:@".0" withString:@""]; is just a quick hack which could easily fail under some peculiar circumstances but hey no one is complaining, at least not yet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a Cocoa app that monitors what you're listening to in iTunes,
I'm working on an app that monitors significant location changes in the background. I've
I'm working on an app that grabs and installs a bunch of updates off
I'm working on an app that requires no user input, but I don't want
I'm working on an app that needs to intercept when a program tries to
I'm working on an App that talks to a serial port, and on my
I'm working on an app that needs to accept a RegEx from the user,
I'm working on an app that will be using https, but we wanted to
I'm working on an app that allows tagging directly on photos via clicking (like
I'm working on an app that sends raw data to zebra printer and print

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.