C#列出所有物理网络适配器的代码

VMware部署Security Onion 2.3全攻略:从环境配置到网络监控实战 网络安全监控(NSM)与安全信息和事件管理(SIEM)是现代企业安全架构的核心,它们通过集中收集、关联分析网络流量与日志事件,实现对威胁的实时检测与响应。其技术原理依赖于深度包检测(DPI)、日志聚合与行为分析引擎。在工程实践中,开源的Security Onion发行版集成了Suricata、Zeek、Wazuh及Elastic Stack等顶级工具,能够快速构建功能完整的监控平台,尤其适用于需要快速进行威胁狩猎与事件调查的场景。本文将聚焦于在VMware虚拟化环境中部署Security Onion 2.3 阅读详情

把写代码过程中常用的一些代码片段备份一次,下面代码是关于C#列出所有物理网络适配器的代码,应该对大家有用。

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;

namespace RobvanderWoude
{
class ListNICs
{
public static ArrayList nics = new ArrayList( );
public static string computer = string.Empty;

	public static string nsrootwmi = computer + "root\WMI";
	public static string nsrootcimv2 = computer + "root\CIMV2";
	public static ManagementObjectCollection wmi1 = searcher1.Get( );
	public static ManagementObjectCollection wmi2 = searcher2.Get( );
	public static ManagementObjectCollection wmi3 = searcher3.Get( );


	static int Main( string[] args )
	{
		try
		{
			bool listBluetooth = true;
			bool listWired = true;
			bool listWireless = true;


			#region Command line parsing


			if ( args.Length > 2 )
			{
				return WriteError( "Invalid command line arguments" );
			}
			if ( args.Length > 0 )
			{
				foreach ( string arg in args )
				{
					if ( arg.StartsWith( "/" ) || arg.StartsWith( "-" ) )
					{
						switch ( arg.ToUpper( ) )
						{
							case "/?":
							case "-?":
								return WriteError( string.Empty );
							case "/B":
							case "/BLUETOOTH":
								if ( ( listBluetooth && listWired && listWireless ) == false )
								{
									return WriteError( "Select a single adapter type only, or omit type to select all" );
								}
								listWired = false;
								listWireless = false;
								break;
							case "/W":
							case "/WIRED":
								if ( ( listBluetooth && listWired && listWireless ) == false )
								{
									return WriteError( "Select a single adapter type only, or omit type to select all" );
								}
								listBluetooth = false;
								listWireless = false;
								break;
							case "/WL":
							case "/WIFI":
							case "/WIRELESS":
								if ( ( listBluetooth && listWired && listWireless ) == false )
								{
									return WriteError( "Select a single adapter type only, or omit type to select all" );
								}
								listBluetooth = false;
								listWired = false;
								break;
							default:
								return WriteError( "Invalid command line argument" );
						}
					}
					else
					{
						if ( !string.IsNullOrEmpty( computer ) )
						{
							return WriteError( "Do not specify more than one computer name" );
						}
						computer = "\\" + arg + "\";
					}

				}
			}


			#endregion Command line parsing


			foreach ( ManagementObject queryObj1 in wmi1 )
			{
				if ( queryObj1["NdisPhysicalMediumType"].ToString( ) == "10" )
				{
					if ( listBluetooth )
					{
						AddAdapter( queryObj1["InstanceName"].ToString( ), "Bluetooth" );
					}
				}
				if ( queryObj1["NdisPhysicalMediumType"].ToString( ) == "0" )
				{
					if ( listWired )
					{
						AddAdapter( queryObj1["InstanceName"].ToString( ), "Wired" );
					}
				}
				if ( queryObj1["NdisPhysicalMediumType"].ToString( ) == "1" )
				{
					if ( listWireless )
					{
						AddAdapter( queryObj1["InstanceName"].ToString( ), "Wireless" );
					}
				}
			}

			nics.Sort( );

			foreach ( string nic in nics )
			{
				Console.WriteLine( nic );
			}


			return 0;
		}
		catch ( Exception e )
		{
			return WriteError( e );
		}
	}


	public static void AddAdapter( string name, string type )
	{
		foreach ( ManagementObject queryObj2 in wmi2 )
		{
			if ( ( queryObj2["Name"].ToString( ) == name ) && Convert.ToBoolean( queryObj2["PhysicalAdapter"] ) )
			{
				foreach ( ManagementObject queryObj3 in wmi3 )
				{
					if ( queryObj3["InstanceName"].ToString( ) == name )
					{
						nics.Add( String.Format( "{0,6}", Convert.ToInt32( queryObj3["NdisLinkSpeed"] ) / 10000 ) + " Mb/st" + String.Format( "{0,-11}", "[" + type + "]" ) + "t" + name );
					}
				}
			}
		}
	}


	#region Error handling


	public static int WriteError( Exception e )
	{
		return WriteError( e == null ? null : e.Message );
	}


	public static int WriteError( string errorMessage )
	{
		ListNICs,  Version 1.00
		List physical network adapters on the specified computer

		Usage:  LISTNICS  [ computername ]  [ /Bluetooth | /Wired | /WireLess ]

		Where:  "computername"    is a remote computer name    (default: this computer)
		        /Bluetooth or /B  list Bluetooth adapters only (default: all)
		        /Wired     or /W  list wired adapters only     (default: all)
		        /Wireless  or /WL list wireless adapters only  (default: all)

		Written by Rob van der Woude

		if ( string.IsNullOrEmpty( errorMessage ) == false )
		{
			Console.Error.WriteLine( );
			Console.ForegroundColor = ConsoleColor.Red;
			Console.Error.Write( "ERROR:  " );
			Console.ForegroundColor = ConsoleColor.White;
			Console.Error.WriteLine( errorMessage );
			Console.ResetColor( );
		}
		Console.Error.WriteLine( );
		Console.Error.WriteLine( "ListNICs,  Version 1.00" );
		Console.Error.WriteLine( "List physical network adapters on the specified computer" );
		Console.Error.WriteLine( );
		Console.Error.Write( "Usage:  " );
		Console.ForegroundColor = ConsoleColor.White;
		Console.Error.Write( "LISTNICS" );
		Console.ResetColor( );
		Console.Error.Write( "  [ computername ]  [ " );
		Console.ForegroundColor = ConsoleColor.White;
		Console.Error.Write( "/B" );
		Console.ResetColor( );
		Console.Error.Write( "luetooth | " );
		Console.ForegroundColor = ConsoleColor.White;
		Console.Error.Write( "/W" );
		Console.ResetColor( );
		Console.Error.Write( "ired | " );
		Console.ForegroundColor = ConsoleColor.White;
		Console.Error.Write( "/W" );
		Console.ResetColor( );
		Console.Error.Write( "ire" );
		Console.ForegroundColor = ConsoleColor.White;
		Console.Error.Write( "L" );
		Console.ResetColor( );
		Console.Error.WriteLine( "ess ]" );
		Console.Error.WriteLine( );
		Console.Error.WriteLine( "Where:  "computername"    is a remote computer name    (default: this computer)" );
		Console.ForegroundColor = ConsoleColor.White;
		Console.Error.Write( "        /B" );
		Console.ResetColor( );
		Console.Error.Write( "luetooth or " );
		Console.ForegroundColor = ConsoleColor.White;
		Console.Error.Write( "/B" );
		Console.ResetColor( );
		Console.Error.WriteLine( "  list Bluetooth adapters only (default: all)" );
		Console.ForegroundColor = ConsoleColor.White;
		Console.Error.Write( "        /W" );
		Console.ResetColor( );
		Console.Error.Write( "ired     or " );
		Console.ForegroundColor = ConsoleColor.White;
		Console.Error.Write( "/W" );
		Console.ResetColor( );
		Console.Error.WriteLine( "  list wired adapters only     (default: all)" );
		Console.ForegroundColor = ConsoleColor.White;
		Console.Error.Write( "        /W" );
		Console.ResetColor( );
		Console.Error.Write( "ire" );
		Console.ForegroundColor = ConsoleColor.White;
		Console.Error.Write( "L" );
		Console.ResetColor( );
		Console.Error.Write( "ess  or " );
		Console.ForegroundColor = ConsoleColor.White;
		Console.Error.Write( "/WL" );
		Console.ResetColor( );
		Console.Error.WriteLine( " list wireless adapters only  (default: all)" );
		Console.Error.WriteLine( );
		Console.Error.WriteLine( "Written by Rob van der Woude" );
		return 1;
	}


	#endregion Error handling
}

}

内网渗透实战:从外网到核心区的三层靶机攻防演练 内网渗透是网络安全攻防演练中的核心环节,它模拟攻击者从外部网络突破边界防御,逐步深入企业内部网络的过程。其基本原理是通过利用Web应用漏洞、系统配置缺陷或弱口令等手段获取初始立足点,再借助代理隧道、端口转发等技术实现横向移动,最终触及核心数据区域。这项技术的价值在于帮助企业识别网络纵深防御体系的薄弱点,提升整体安全防护能力。在实际应用场景中,内网渗透技术广泛应用于红蓝对抗、渗透测试和安全评估。本文以CFS三层靶机为例,详细解析了从外网信息收集、Web渗透、内网横向移动到权限提升的完整攻击链,并重点介绍了反向 阅读详情

相关推荐

c# 多网卡 由【网络适配器名】获取网卡信息,IP

c# 多网卡 由【网络适配器名】获取网卡信息,IP 多网卡电脑中,网络适配器的名字 多样化! 项目中需要,根据网络适配器 名字 获取 单个网卡的IP: class Program { static void Main(string[] args) { Console.WriteLine(GetIPv4Ad...

Luffy's blogs 2848

C#列出所有物理网络适配器的方法

主要介绍了C#列出所有物理网络适配器的方法,实例分析了C#操作网络设备的技巧,具有一定参考借鉴价值,需要的朋友可以参考下

【信息科学与工程学】【运营科学】第二篇 C4信息与通信网络运营 (C4) ——数据中心网络运营04

典型值:λ1​∈[−0.02,−0.01], λ2​∈[−0.01,0], η1​,η3​∈[0.1,0.3], η2​,η4​∈[0.05,0.15]参数:δ1​∈[−0.8,−0.3], δ2​∈[−0.5,−0.2], δ3​∈[−0.4,−0.1], δ4​∈[−0.6,−0.2]参数:φ1​∈[0.1,0.3], φ2​∈[−0.2,−0.05], φ3​∈[−0.1,0.1], φ4​∈[−0.3,−0.1]参数:α∈[0.3,0.6], β∈[0.2,0.4], γ∈[0.01,0.03]

weixin_49199313的博客 1029

C#获取所有适配器的名称、描述、状态、接口

public class TSAdapter { /// <summary> /// 适配器的名称 /// </summary> public string Name; /// <summary> /// 适配器的描述 /// </summary> public string Description; /// <summary> /// 适配器的服务名 //

君一席 931

如何用C# 获取网络适配器中的的IP

C#中,可以使用System.Net.NetworkInformation命名空间下的NetworkInterface类来获取和管理本地计算机上的网络适配器。以下是使用C#获取网络适配器IP地址的代码示例:```csharp using System; using System.Net.NetworkInformation; namespace ConsoleApp1 { cla...

zls365365的博客 480

C# .NET 中使用 WMI 查找所有网络适配器

在这篇文章中,我们看到了如何使用 Windows Management Intrumentation (WMI) 检索所有逻辑驱动器。我们将采用非常相似的技术来枚举所有网络适配器。 以下代码打印在本地 - “root” - 计算机上找到的所有网络驱动器的所有非空属性: using System; using System.Collections.Concurrent; using System.Threading; using System.Threading.Tasks; using static

allway2的博客 635

C#获取当前主机硬件信息

using System;   using System.Collections.Generic;   using System.Linq;   using System.Text;   using System.Threading.Tasks;         using System.Net;   using System.Management;  //在项目-》添加引用...

yw1688的专栏 2027

软考-系统分析师-备考笔记

根据学习视频和一些资料整理的软考系统分析师考试笔记,2025年下半年通关

提子同学是我 970

MAC地址获取,有线网卡与无线网卡、物理网卡与虚拟网卡的区分

获取当前活跃状态的网卡MAC地址、物理地址 Wmic命令:Win32_NetworkAdapter和Win32_NetworkAdapterConfiguration。 其中cmd命令行执行: 1. Wmic Path Win32_NetworkAdapter get GUID,MACAddress,NetEnabled,PhysicalAdapter,Index 备注: GU...

diefu7606的博客 1752

C# 获取本机网卡信息、个数、描述信息、类型、速度等

代码比较简单,直接上图上码。 实现代码有注释,以下是该例子的完整代码。 引入命名空间: using System.Net.NetworkInformation; using System.Net; 完整代码: namespace NetworkInterfaceExample { public partial class Form1 : Form { public Form1() { InitializeComponent();

波波诸葛伟 1431

2分钟解决联想电脑wifi功能消失 网络适配器错误代码56

2分钟解决联想电脑wifi功能消失 网络适配器错误代码56。

weixin_42999968的博客 1732

网络适配器感叹号(代码56)

网络适配器变成感叹号 无论怎么重启\重装网卡驱动都不行, 且查看属性显示类被调用,代码56 先卸载虚拟机, 再去services.msc里停用所有VM开头的服务, 最后下载ccleaner清理注册表, 重启电脑, 顺利解决 如果有帮助到你请点个赞吧QuQ ...

weixin_48682444的博客 5377

C# 获取适配器网络连接IP地址,子网掩码,DNS,数据包等信息

你可以大致通过cmd 输入ipconfig获得以太网的适配信息(下面只涉及以太网),其中所有列出的就是以下代码运行后将统计出来的,只是代码多得到的结果更丰富,包括 适配器接口的名称,标识符,连接状态,IP地址,子网掩码,默认网关,mac地址,所有DNS服务器地址,网络接口速度,以及数据包的相关信息。 在我的电脑运行-cmd输入ipconfig结果如下: 代码如下: using System;

king1991wbs的专栏 1万+

笔记本蓝牙崩溃、图标消失不能打开蓝牙功能-解决办法(由于蓝牙串口连接出现的问题)

学单片机遇到蓝牙崩溃的问题 解决蓝牙串口发送时,蓝牙功能突然消失如下图: 原因: 单片机发送速度太快了,串口不断向电脑发送数据,导致电脑端崩溃。 解决办法:本人前前后后这种情况出现了6次。总结方法如下:(3个方法,有的网友是在bios系统开启,我没试过。我列出的方法中实在前两种不好使就用第三个。第三种我成功了4次) 1. WIN+R 输入:services.msc 打开服务:然后将B英文开头的...

sf9090的博客 1万+

设计模式——适配器模式(附代码示例)

一. 适配器模式 1. 概念 适配器模式(Adapter Rattern)将某个类的接口转换成客户端期望的另一个接口表示,主的目的是兼容性,让原本因接口不匹配不能一起工作的两个类可以协同工作。其别名为包装器(Wrapper)。类比,U盘插个转换头可用与手机type-c接口相连接;或者是使用多功能转换插头,实现三孔插头与两孔插座相连。 2. 工作原理 适配器模式将一个类的接口转换成另一种接口,让原本接口不兼容的类可以兼容。从用户的角度看不到被适配者,是解耦的;用户调用适...

枫陵的博客 3038

<转载>C# .NET 获取网络适配器信息

1:NetworkInterface 类: 该类位于 System.Net.NetworkInformation 命名空间 该类可以方便的检测本机有多少个网卡(网络适配器),网卡信息,哪些网络连接可用等。 2:常用方法和属性: view sourceprint? NetworkInterface[] adapters...

anyangqu5692的博客 662
上一篇: 视频制作软件,剪视频的软件哪个好?
下一篇: 科普一下王者剪辑软件里面的“克隆大师”功能
dahlia548
博客等级 码龄7年 2粉丝 10原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值