TCP/IP实验获取主机网卡信息
来源:互联网 发布:中国网络日报。 编辑:程序博客网 时间:2024/04/30 05:53
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using SharpPcap;using PacketDotNet;using SharpPcap.LibPcap;namespace Text{ public partial class Form1 : Form { CaptureDeviceList device_list; public Form1() { InitializeComponent(); device_list = GetDeviceList(); } /// <summary> /// 获得当前的设备列表(网卡) /// </summary> /// <returns></returns> public CaptureDeviceList GetDeviceList() { // Print SharpPcap version string ver = SharpPcap.Version.VersionString; this.richTextBox1.Text = string.Format("SharpPcap {0}, Device List\n", ver); try { // Retrieve the device list CaptureDeviceList device_list = CaptureDeviceList.Instance; // If no devices were found print an error if (device_list.Count < 1) { this.richTextBox1.Text += "No devices were found on this machine\n"; return null; } this.richTextBox1.Text += "\nThe following devices are available on this machine:\n"; this.richTextBox1.Text +="----------------------------------------------------\n"; // Print out the available network devices foreach (ICaptureDevice dev in device_list) this.richTextBox1.Text += string.Format("\n名称:{0}\n网关:{1}\n描述:{2}\n", ((PcapDevice)dev).Interface.FriendlyName, ((PcapDevice)dev).Interface.GatewayAddress, ((PcapDevice)dev).Interface.Description); return device_list; } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); return null; } }}}
实验结果
SharpPcap 采用了分层结构,在最顶层的是几个管理所有设备的类:
CaptureDeviceList——包含系统中所有设备的列表
ICaptureDevice——所有继承 ICaptureDevice 接口的设备
通过执行下面一行代码,可以轻松获得所有本机的所有网卡设备:
CaptureDeviceListdevice_list = CaptureDeviceList.Instance;
在获得网卡设备以后,通过下面的 foreach 循环,就能将设备信息输出到RichTextBox 中:
foreach (ICaptureDevice devindevice_list)
this.richTextBox1.Text+=string.Format("\n名称:{0}\n网关:{1}\n描述:{2}\n", ((PcapDevice)dev).Interface.FriendlyName,((PcapDevice)dev).Interface.GatewayAddress, ((PcapDevice)dev).Interface.Description);
阅读全文
0 0
- TCP/IP实验获取主机网卡信息
- VC++实现获取本地主机网卡信息
- 获取一个主机的IP,MAC信息
- 获取IP地址及网卡信息
- 获取ip地址及网卡信息
- c#获取网卡的ip等信息
- MSDN例子 获取网卡、ip等信息
- linux下libpcap 获取当前主机的网卡信息
- 主机上有多个网卡用java指定获取某一个网卡ip的问题
- 获取主机MAC IP Mask Gateway的信息
- C++获取计算机主机信息(计算机名称、IP)
- QT---Winsocket获取网关(Gateway) 主机IP等信息
- 获取请求主机的IP端口等信息
- C++获取计算机主机信息(计算机名称、IP)
- c#获取和设置网卡ip/dns等信息
- GetAdaptersInfo 获取网卡配置和Ip地址信息
- [VC++]编程获取系统网卡列表及IP地址信息
- linux下C编程_获取指定网卡IP信息
- 八.ARM裸机学习之S5PV210的时钟系统1(原理概念及框图分析)
- Tomcat溢出、Java内存溢出
- linux mint下安装apache,php
- 1174 明明的随机数
- 小白快速部署Spark-2.2.0集群(附通俗解释)
- TCP/IP实验获取主机网卡信息
- vs2017 活动解决方案或项目由选择的源代码管理插件以外的插件管理
- 一名IT小白—为编程而奋斗
- The partial sum problem 搜索
- 大数据Spark07_SparkShell、SparkUI界面、SparkHA、SparkShuffle、Spark内存管理
- 求最长回文子串
- Leetcode(W8):121. Best Time to Buy and Sell Stock(动态规划)
- JAVA口碑IDE工具IntelliJ IDEA入门高清
- 数据结构实验之二叉树一:树的同构