标题:如何用C#获取交换机的IP,mac之类的参数!!!急
只看楼主
不悔人
Rank: 2
等 级:论坛游民
帖 子:37
专家分:37
注 册:2009-10-21
结帖率:80%
 问题点数:0 回复次数:0 
如何用C#获取交换机的IP,mac之类的参数!!!急
c#遍历局域网中所有IP地址  最好有源码


using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using
using
using System.Threading;
namespace IPOK
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            IPAddress[] IP = Dns.GetHostAddresses("");
            String ip1 = IP[0].ToString();
            ip.Text = ip1;
            hostname.Text = Dns.GetHostName();
          //  IPAddress[] adss = ;
           
            NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface adapter in adapters)
            {

                IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
                IPAddressCollection dnsServers = adapterProperties.DnsAddresses;
                if (dnsServers.Count > 0)
                {
                  // l1.Text=adapter.Description;
                    l1.Text = adapter.Description;
                    foreach (IPAddress dns in dnsServers)
                    {
                        DNS.AppendText("  DNS Servers:"+dns.ToString());
                    

                           
                    }
                    Console.WriteLine();
                }
            }


            this.ip.Text = "";
            //Thread 类: 创建并控制线程
            //Thread thScan = new Thread(new ThreadStart(ScanTarget));
            Thread thScan = new Thread(new ThreadStart(ScanTarget));
            //Thread.Start 方法:启动线程
            thScan.Start();
        }

        private void ScanTarget()
        {
            NumericUpDown numericUpDown1 = new NumericUpDown();
            NumericUpDown numericUpDown2 = new NumericUpDown();
            NumericUpDown numericUpDown3 = new NumericUpDown();
            NumericUpDown numericUpDown4 = new NumericUpDown();
            NumericUpDown numericUpDown5 = new NumericUpDown();
            //构造IP地址的31-8BIT 位,也就是固定的IP地址的前段
            // numericUpDown1是定义的System.Windows.Forms.NumericUpDown控件
            string strIPAddress = numericUpDown1.Text + "." + numericUpDown2.Text + "." + numericUpDown3.Text + ".";
            //开始扫描地址
            int nStrat = Int32.Parse(numericUpDown4.Text);
            //终止扫描地址
            int nEnd = Int32.Parse(numericUpDown5.Text);
            //扫描的操作
            for (int i = nStrat; i <= nEnd; i++)
            {
                string strScanIPAdd = strIPAddress + i.ToString();
                //转换成IP地址
                IPAddress myScanIP = IPAddress.Parse(strScanIPAdd);
                try
                {
                    //你可以加入自已的,增强功能
                    // Dns.GetHostByAddress 方法: 根据 IP 地
                    //址获取 DNS 主机信息。
                  
                    //获取主机的名
                    IPAddress[] IP = Dns.GetHostAddresses("");
                    string strHostName = IP[0].ToString();
                    ip.AppendText(strScanIPAdd + "->" + strHostName + "\r");
                }
                catch (Exception error)
                {
                    MessageBox.Show(error.Message);
                }
            }




        }

        private void Form1_Load(object sender, EventArgs e)
        {
           
        }

     


    }
}



哪错了  唉 !!!紧急
搜索更多相关主题的帖子: mac 获取 交换机 参数 
2009-10-22 15:18



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-289504-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.103403 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved