最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#列出所有物理網(wǎng)絡(luò)適配器的方法

 更新時(shí)間:2015年04月18日 12:19:22   作者:work24  
這篇文章主要介紹了C#列出所有物理網(wǎng)絡(luò)適配器的方法,實(shí)例分析了C#操作網(wǎng)絡(luò)設(shè)備的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了C#列出所有物理網(wǎng)絡(luò)適配器的方法。分享給大家供大家參考。具體如下:

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;
  // Use global variables, so we only need to run the WMI queries once
  public static string nsrootwmi = computer + "root\\WMI";
  public static string nsrootcimv2 = computer + "root\\CIMV2";
  public static ManagementObjectSearcher searcher1 = new ManagementObjectSearcher( nsrootwmi, "SELECT * FROM MSNdis_PhysicalMediumType" );
  public static ManagementObjectCollection wmi1 = searcher1.Get( );
  public static ManagementObjectSearcher searcher2 = new ManagementObjectSearcher( nsrootcimv2, "SELECT * FROM Win32_NetworkAdapter" );
  public static ManagementObjectCollection wmi2 = searcher2.Get( );
  public static ManagementObjectSearcher searcher3 = new ManagementObjectSearcher( nsrootwmi, "SELECT * FROM MSNdis_LinkSpeed" );
  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
    // Only 2 optional argument allowed: remote computer name and/or adapter type
    if ( args.Length > 2 )
    {
     return WriteError( "Invalid command line arguments" );
    }
    if ( args.Length > 0 )
    {
     foreach ( string arg in args )
     {
      // We'll display a 'friendly' message if help was requested
      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/s\t" + 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 )
  {
   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
 }
}

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • c# 繪制中國(guó)象棋棋盤(pán)與棋子

    c# 繪制中國(guó)象棋棋盤(pán)與棋子

    這篇文章主要介紹了c# 繪制中國(guó)象棋棋盤(pán)與棋子,文中實(shí)例代碼非常詳細(xì),幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-07-07
  • C#中的多態(tài)深入理解

    C#中的多態(tài)深入理解

    如果面試時(shí)主考官要求你用一句話來(lái)描述多態(tài),盡可能的精煉,你會(huì)怎么回答?當(dāng)然答案有很多,每個(gè)人的理解和表達(dá)不盡相同,但我比較趨向這樣描述:通過(guò)繼承實(shí)現(xiàn)的不同對(duì)象調(diào)用相同的方法,表現(xiàn)出不同的行為,稱(chēng)之為多態(tài)
    2014-01-01
  • C# 利用代理爬蟲(chóng)網(wǎng)頁(yè)的實(shí)現(xiàn)方法

    C# 利用代理爬蟲(chóng)網(wǎng)頁(yè)的實(shí)現(xiàn)方法

    這篇文章主要介紹了C# 利用代理爬網(wǎng)頁(yè)的實(shí)現(xiàn)方法的相關(guān)資料,希望通過(guò)本能幫助到大家實(shí)現(xiàn)這樣的功能,需要的朋友可以參考下
    2017-10-10
  • C#中的枚舉類(lèi)型(Enum)介紹

    C#中的枚舉類(lèi)型(Enum)介紹

    這篇文章介紹了C#中的枚舉類(lèi)型(Enum),文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-07-07
  • 利用C#實(shí)現(xiàn)獲取與監(jiān)控電腦系統(tǒng)信息

    利用C#實(shí)現(xiàn)獲取與監(jiān)控電腦系統(tǒng)信息

    在C#中,獲取與監(jiān)控電腦系統(tǒng)信息通??梢酝ㄟ^(guò)多種方式實(shí)現(xiàn),這篇文章主要為大家整理了幾種常見(jiàn)的方法及其示例代碼,希望對(duì)大家有所幫助
    2024-11-11
  • C#裝箱和拆箱的原理介紹

    C#裝箱和拆箱的原理介紹

    這篇文章介紹了C#裝箱和拆箱的原理,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-03-03
  • C#使用DateTime獲取日期和時(shí)間的實(shí)現(xiàn)

    C#使用DateTime獲取日期和時(shí)間的實(shí)現(xiàn)

    在C#中,DateTime類(lèi)是用來(lái)處理日期和時(shí)間的類(lèi),它具有許多屬性和方法,用于操作和獲取日期和時(shí)間的不同部分,本文就來(lái)介紹一下C#使用DateTime獲取,感興趣的可以了解一下
    2023-11-11
  • Unity UGUI的Image圖片組件使用詳解

    Unity UGUI的Image圖片組件使用詳解

    這篇文章主要為大家介紹了Unity UGUI的Image圖片組件使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07
  • 在.net應(yīng)用程序中運(yùn)行其它EXE文件的方法

    在.net應(yīng)用程序中運(yùn)行其它EXE文件的方法

    這篇文章主要介紹了在.net應(yīng)用程序中運(yùn)行其它EXE文件的方法,涉及C#進(jìn)程操作的相關(guān)技巧,需要的朋友可以參考下
    2015-05-05
  • C#中AS和IS關(guān)鍵字的用法

    C#中AS和IS關(guān)鍵字的用法

    這篇文章主要介紹了C#中AS和IS關(guān)鍵字的用法的相關(guān)資料,需要的朋友可以參考下
    2016-03-03

最新評(píng)論

金平| 莱西市| 大同县| 苏尼特右旗| 婺源县| 苏州市| 襄樊市| 韩城市| 临洮县| 山阴县| 筠连县| 民权县| 江安县| 黄梅县| 铁岭县| 英超| 库尔勒市| 永泰县| 太仓市| 邮箱| 云南省| 金乡县| 南华县| 中山市| 静安区| 南开区| 永顺县| 报价| 利津县| 枣强县| 怀化市| 库车县| 柳江县| 庆阳市| 永顺县| 岫岩| 临漳县| 南汇区| 资溪县| 榆林市| 彩票|