Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
230 views
in Technique[技术] by (71.8m points)

macos - C# Xamarian & .NET Monitoring Network Traffic Mac OSX

Currently, using JetBrains Rider as the IDE. I am running a basic example Xamarian application template for the Mac OSX desktop. Simply by creating a new project and editing the Main.cs only to test a simple idea.

The simple basic code added into Main.cs is:

using System;
using System.Net.NetworkInformation;

    class MainClass
    {
        static void Main()
        {
            if (!NetworkInterface.GetIsNetworkAvailable())
               return;
    
            NetworkInterface[] interfaces 
                = NetworkInterface.GetAllNetworkInterfaces();
    
            foreach (NetworkInterface ni in interfaces)
            {                
                Console.WriteLine("    Bytes Sent: {0}", 
                    ni.GetIPv4Statistics().BytesSent);
                Console.WriteLine("    Bytes Received: {0}",
                    ni.GetIPv4Statistics().BytesReceived);
            }
        }
    }

Presently, I sometimes know network traffic monitoring on interfaces requires Sudo permissions so I even opened the IDE up with Sudo permissions and it does not output any bytes incoming or out outgoing. Always, zero traffic logged.

Any ideas on network traffic monitoring in C# Mac OSX with IP address's of destination capabilities or how to allow something basic such as this to work.

Output Bytes Sent 0

Referencing: Documentation - Microsoft - NetworkInformation.IPv4InterfaceStats...

question from:https://stackoverflow.com/questions/65932151/c-sharp-xamarian-net-monitoring-network-traffic-mac-osx

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...