如何用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)
{
}
}
}
哪错了 唉 !!!紧急