每隔個N年莫名其妙都會遇到這個問題,筆記一下首先感恩 sharppcap 這個套件,無腦用 nuget 安裝完即可 開心的複製貼上 example 馬上就 gg 了 炸了這個 error wpcap.dll was not found 查了下才發先原來要安裝 Win10Pcap 接著無腦 coding , 可以看他的 example 比較雷的是要用 Open 去打開,有點麻煩 @@!
using SharpPcap; using SharpPcap.LibPcap; using SharpPcap.Npcap; using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks;
namespaceConsoleAppFetchMacAddress { publicclassProgram { ///<summary> /// Obtaining the device list ///</summary> publicstaticvoidMain(string[] args) { // Print SharpPcap version string ver = SharpPcap.Version.VersionString; Console.WriteLine( "SharpPcap {0}, Example1.IfList.cs", ver );
// Retrieve the device list var devices = CaptureDeviceList.Instance;
// If no devices were found print an error if (devices.Count < 1) { Console.WriteLine( "這台機器上沒有任何設備" ); return; }
Console.WriteLine( "\nThe following devices are available on this machine:" ); Console.WriteLine( "----------------------------------------------------\n" );
/* Scan the list printing every entry */ foreach (LibPcapLiveDevice dev in devices) { //注意這個要打開不然沒辦法跑客製化的 code dev.Open( );