网络编程技术2021-09-03之输出本机网卡信息

输出本机网卡信息

1.文件MainWindow.xaml

<Window x:Class="w3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:w3"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <TextBox x:Name="textBox" HorizontalAlignment="Left" Margin="223,82,0,0" Text="" TextWrapping="Wrap" VerticalAlignment="Top" Width="367" Height="231"/>
        <Button Content="网卡" HorizontalAlignment="Center" Margin="0,360,0,0" VerticalAlignment="Top" Height="32" Width="54" Click="Button_Click_1"/>

    </Grid>
</Window>

2.文件MainWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Net;
using System.Net.Sockets;
using System.Net.NetworkInformation;
namespace w3
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private String GetAllWK() {
            StringBuilder sb = new StringBuilder();
            NetworkInterface[] nis = NetworkInterface.GetAllNetworkInterfaces();
            int cs = nis.Length;
            int i = 0;
            while (i < cs) {
                NetworkInterface ni = nis[i];
                sb.AppendLine("==========第"+ i +"个网卡========");
                sb.AppendLine("Description:" + ni.Description);
                sb.AppendLine("Name:"+ ni.Name);
                sb.AppendLine("Speed:"+ ni.Speed);
                sb.AppendLine("该接口收到的字节数:" + ni.GetIPStatistics().BytesReceived.ToString());
                sb.AppendLine("该接口发送的字节数:" + ni.GetIPStatistics().BytesSent.ToString());
                sb.AppendLine("该接口丢弃的传入数据包数:" + ni.GetIPStatistics().IncomingPacketsDiscarded.ToString());
                sb.AppendLine("该接口丢弃的传出数据包数:" + ni.GetIPStatistics().OutgoingPacketsDiscarded.ToString());
                sb.AppendLine("该接口有错误的的传入数据包数:" + ni.GetIPStatistics().IncomingPacketsWithErrors.ToString());
                //sb.AppendLine("========================");
                i++;
            }
            return sb.ToString();
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            textBox.Text = GetAllWK();
        }
    }
}

效果:
在这里插入图片描述

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值