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.
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)
|