- 积分
- 40165
- 好友
- 记录
- 主题
- 帖子
- 听众
- 收听
|
发表于 2013-3-19 11:03:29
|
显示全部楼层
我想你要的应该是这样的数据吧
C#本地网络连连名称
[code=csharp] private void Form1_Load(object sender, EventArgs e)
{
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in nics)
{
bool Pd1 = (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet); //判断是否是以太网连接
if (Pd1)
{
comboBox1.Items.Add("网络适配器名称:" + adapter.Name);
//comboBox1.Items.Add("网络适配器标识符:" + adapter.Id);
//comboBox1.Items.Add("适配器连接状态:" + adapter.OperationalStatus.ToString());
IPInterfaceProperties ip = adapter.GetIPProperties(); //IP配置信息
if (ip.UnicastAddresses.Count > 0)
{
//comboBox1.Items.Add("IP地址:" + ip.UnicastAddresses[0].Address.ToString());
//comboBox1.Items.Add("子网掩码:" + ip.UnicastAddresses[0].IPv4Mask.ToString());
}
if (ip.GatewayAddresses.Count > 0)
{
//comboBox1.Items.Add("默认网关:" + ip.GatewayAddresses[0].Address.ToString()); //默认网关
}
int DnsCount = ip.DnsAddresses.Count;
//comboBox1.Items.Add("DNS服务器地址:"); //默认网关
if (DnsCount > 0)
{
//其中第一个为首选DNS,第二个为备用的,余下的为所有DNS为DNS备用,按使用顺序排列
for (int i = 0; i < DnsCount; i++)
{
comboBox1.Items.Add(" " + ip.DnsAddresses.ToString());
}
}
//comboBox1.Items.Add("网络接口速度:" + (adapter.Speed / 1000000).ToString("0.0") + "Mbps");
//comboBox1.Items.Add("接口描述:" + adapter.Description);
//comboBox1.Items.Add("适配器的媒体访问控制 (MAC) 地址:" + adapter.GetPhysicalAddress().ToString());
//comboBox1.Items.Add("该接口是否只接收数据包:" + adapter.IsReceiveOnly.ToString());
//comboBox1.Items.Add("该接口收到的字节数:" + adapter.GetIPv4Statistics().BytesReceived.ToString());
//comboBox1.Items.Add("该接口发送的字节数:" + adapter.GetIPv4Statistics().BytesSent.ToString());
//comboBox1.Items.Add("该接口丢弃的传入数据包数:" + adapter.GetIPv4Statistics().IncomingPacketsDiscarded.ToString());
//comboBox1.Items.Add("该接口丢弃的传出数据包数:" + adapter.GetIPv4Statistics().OutgoingPacketsDiscarded.ToString());
//comboBox1.Items.Add("该接口有错误的传入数据包数:" + adapter.GetIPv4Statistics().IncomingPacketsWithErrors.ToString());
//comboBox1.Items.Add("该接口有错误的传出数据包数:" + adapter.GetIPv4Statistics().OutgoingPacketsWithErrors.ToString());
//comboBox1.Items.Add("该接口协议未知的数据包数:" + adapter.GetIPv4Statistics().IncomingUnknownProtocolPackets.ToString());
//comboBox1.Items.Add("---------------------------------------------------------------------\n");
}
}
}[/code]
|
|