hostList=newDictionary();DirectoryEntryMainGroup=newDirectoryEntry("WinNT:");foreach(DirectoryEntrydomaininMainGroup.Children){foreach(DirectoryEntrypcindomain.Children){try{Sy" />

亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

獲取局域網計算機名以及IP以及mac地址

系統 2541 0
        
          void
        
        
           GetAll()

        {

            IDictionary
        
        <
        
          string
        
        , 
        
          string
        
        > hostList = 
        
          new
        
         Dictionary<
        
          string
        
        , 
        
          string
        
        >
        
          ();

            DirectoryEntry MainGroup 
        
        = 
        
          new
        
         DirectoryEntry(
        
          "
        
        
          WinNT:
        
        
          "
        
        
          );

            
        
        
          foreach
        
         (DirectoryEntry domain 
        
          in
        
        
           MainGroup.Children)

            {

                
        
        
          foreach
        
         (DirectoryEntry pc 
        
          in
        
        
           domain.Children)

                {

                    
        
        
          try
        
        
          

                    {

                        System.Net.IPAddress[] remoteHost 
        
        =
        
           Dns.GetHostAddresses(pc.Name);

                        hostList.Add(pc.Name, remoteHost[
        
        
          0
        
        
          ].ToString());

                    }

                    
        
        
          catch
        
        
           { }

                }

            }

            
        
        
          using
        
         (StreamWriter sw = 
        
          new
        
         StreamWriter(
        
          "
        
        
          c:\\pp.txt
        
        
          "
        
        , 
        
          true
        
        
          ))

            {

                
        
        
          foreach
        
         (KeyValuePair<
        
          string
        
        , 
        
          string
        
        > child 
        
          in
        
        
           hostList)

                {

                    sw.WriteLine(Environment.NewLine 
        
        + 
        
          "
        
        
          name:
        
        
          "
        
         + child.Key + 
        
          "
        
        
            ip:
        
        
          "
        
         +
        
           child.Value);

                }

                sw.Flush();

                sw.Close();

            }

        }
        
      
View Code

以上把局域網的計算機以及IP保存到c盤

再根據ip地址獲取mac地址

        
          public
        
        
          string
        
         GetMac(
        
          string
        
        
           IP)

        {

            
        
        
          string
        
         dirResults = 
        
          ""
        
        
          ;

            ProcessStartInfo psi 
        
        = 
        
          new
        
        
           ProcessStartInfo();

            Process proc 
        
        = 
        
          new
        
        
           Process();

            psi.FileName 
        
        = 
        
          "
        
        
          nbtstat
        
        
          "
        
        
          ;

            psi.RedirectStandardInput 
        
        = 
        
          false
        
        
          ;

            psi.RedirectStandardOutput 
        
        = 
        
          true
        
        
          ;

            psi.Arguments 
        
        = 
        
          "
        
        
          -A   
        
        
          "
        
         +
        
           IP;

            psi.UseShellExecute 
        
        = 
        
          false
        
        
          ;

            proc 
        
        =
        
           Process.Start(psi);

            dirResults 
        
        =
        
           proc.StandardOutput.ReadToEnd();

            proc.WaitForExit();

            dirResults 
        
        = dirResults.Replace(
        
          "
        
        
          \r
        
        
          "
        
        , 
        
          ""
        
        ).Replace(
        
          "
        
        
          \n
        
        
          "
        
        , 
        
          ""
        
        ).Replace(
        
          "
        
        
          \t
        
        
          "
        
        , 
        
          ""
        
        
          );

            Regex reg 
        
        = 
        
          new
        
         Regex(
        
          "
        
        
          Mac[   ]{0,}Address[   ]{0,}=[   ]{0,}(?<key>((.)*?))__MAC
        
        
          "
        
        , RegexOptions.IgnoreCase |
        
           RegexOptions.Compiled);

            Match mc 
        
        = reg.Match(dirResults + 
        
          "
        
        
          __MAC
        
        
          "
        
        
          );



            
        
        
          if
        
        
           (mc.Success)

            { 
        
        
          return
        
         mc.Groups[
        
          "
        
        
          key
        
        
          "
        
        
          ].Value; }

            
        
        
          else
        
        
          

            {

                reg 
        
        = 
        
          new
        
         Regex(
        
          "
        
        
          Host   not   found
        
        
          "
        
        , RegexOptions.IgnoreCase |
        
           RegexOptions.Compiled);

                mc 
        
        =
        
           reg.Match(dirResults);

                
        
        
          if
        
        
           (mc.Success)

                {

                    
        
        
          return
        
        
          "
        
        
          Host   not   found!
        
        
          "
        
        
          ;

                }

                
        
        
          else
        
        
          

                { 
        
        
          return
        
        
          ""
        
        
          ; }

            }

        }
        
      
View Code

需要的稍作更改即可使用

獲取局域網計算機名以及IP以及mac地址


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 神马影院不卡不卡在线观看 | 日韩欧美 在线播放 | 欧美另类亚洲 | 久久综合九色综合97_ 久久久 | 色综合久久夜色精品国产 | 五月花精品视频在线观看 | 波多野一区二区三区在线 | 人人爽天天碰天天躁夜夜躁 | 6一10周岁毛片免费 6一10周岁毛片在线 | 日韩一区二区视频在线观看 | 国产91久久精品一区二区 | 日本a在线观看 | 激情五月宗合网 | 久久剧场 | a免费国产一级特黄aa大 | 欧美另类丰满69xxxxx | 中文字幕日本精品一区二区三区 | 亚洲欧美字幕 | 国产精品久久久久久久网站 | 九色最新网址 | 亚洲成人在线网 | 999在线免费视频 | 日本一本一区二区 | 伊人网站在线观看 | 97影院网 | 久久精品视频网 | 国产精品国产亚洲精品不卡 | 亚洲成人免费在线 | 国产亚洲精品久久久久久牛牛 | 高清视频 一区二区三区四区 | 激情亚洲 | 日韩久久免费视频 | 欧美 亚洲 另类 热图 | 亚洲一区二区三区高清 | 国模无水印一区二区三区 | 国产一区二区三区视频在线观看 | 欧美激情社区 | 一级a性色生活片毛片 | 亚洲图片综合区另类图片 | 免费视频精品一区二区三区 | 最新永久地址 |