This article is a mirror article of machine translation, please click here to jump to the original article.

View: 43222|Reply: 1

[Source] .NET Core in Linux traffic capture

[Copy link]
Posted on 2021-1-19 11:50:07 | | | |
SharpPcap is a cross-platform traffic capture software that can operate with .NET, a fully managed cross-platform (Windows, Mac, Linux) .NET library for capturing packets from live and file-based devices.
.net is written by SharpPcap, a packet capture tool
https://www.itsvse.com/thread-2914-1-1.html

GitHub address:The hyperlink login is visible.

A new .NET Core 3.1 console project with the following C# demo code is as follows:


Publish your project to a Linux server (Publishing must not be set to generate a single file!! Publishing must not be set to generate a single file!! Publishing must not be set to generate a single file!!), the error is as follows:

SharpPcap 5.4.0.0, CreatingCaptureFile
Unhandled exception. System.DllNotFoundException: Unable to load shared library 'libpcap' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibpcap: cannot open shared object file: No such file or directory
   at SharpPcap.LibPcap.Unix.pcap_findalldevs(IntPtr& alldevs, StringBuilder errbuf)
   at SharpPcap.LibPcap.LibPcapSafeNativeMethods.pcap_findalldevs(IntPtr& alldevs, StringBuilder errbuf)
   at SharpPcap.LibPcap.PcapInterface.GetAllPcapInterfaces()
   at SharpPcap.LibPcap.LibPcapLiveDeviceList.GetDevices()
   at SharpPcap.LibPcap.LibPcapLiveDeviceList.Refresh()
   at SharpPcap.LibPcap.LibPcapLiveDeviceList.. ctor()
   at SharpPcap.LibPcap.LibPcapLiveDeviceList.get_Instance()
   at Linux_Packets.Program.Main(String[] args)
Aborted (core dumped)


The error is caused because the server does not install libpcap, server system: CentOS Linux release 8.2.2004 (Core)

libpcap official website:The hyperlink login is visible.


Installing GCC:

Installing Flex:



Without flex, installing libpcap directly will prompt: configure: error: Neither flex nor lex was found



To install bison:



If you don't install it, the error will be as follows:


configure: error: yacc is insufficient to compile libpcap.
libpcap requires Bison, a newer version of Berkeley YACC with support
for reentrant parsers, or another YACC compatible with them.
Finally, download and install libpcap

We install the latest version of libpcap-1.10.0, which is installed under the /usr/local/lib directory by default.

My program directory is /root/dotnet/ So, needCreate soft connections, the command is as follows:


Remember that the program needs to be granted execution permissions before it can be run, as follows:

The program can run normally on Linux, as shown in the figure below:



(End)




Previous:.NET/C# to get the CPU and memory usage of the specified process
Next:OpenTelemetry OpenTracing OpenCensus information collection and data collection
 Landlord| Posted on 2025-9-26 10:53:52 |
.NET/C# uses WinDivert to capture packets and modify packets on Windows
https://www.itsvse.com/thread-11078-1-1.html
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com