Skip to content

Commit

Permalink
Added AdapterInfo class (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Sep 16, 2023
1 parent b72dcb6 commit b174b96
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions InternetTest/InternetTest/Classes/AdapterInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
MIT License
Copyright (c) Léo Corporation
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

using System.Net.NetworkInformation;

namespace InternetTest.Classes
{
public class AdapterInfo
{
public string Name { get; set; }
public NetworkInterfaceType NetworkInterfaceType { get; set; }
public OperationalStatus Status { get; set; }
public string IpVersion { get; set; }
public string DnsSuffix { get; set; }
public int Mtu { get; set; }
public bool DnsEnabled { get; set; }
public bool IsDynamicDnsEnabled { get; set; }
public bool IsReceiveOnly { get; set; }
public bool SupportsMulticast { get; set; }
public long Speed { get; set; }
public long BytesReceived { get; set; }
public long BytesSent { get; set; }
public long IncomingPacketsDiscarded { get; set; }
public long IncomingPacketsWithErrors { get; set; }
public long IncomingUnknownProtocolPackets { get; set; }
public long NonUnicastPacketsReceived { get; set; }
public long NonUnicastPacketsSent { get; set; }
public long OutgoingPacketsDiscarded { get; set; }
public long OutgoingPacketsWithErrors { get; set; }
public long OutputQueueLength { get; set; }
public long UnicastPacketsReceived { get; set; }
public long UnicastPacketsSent { get; set; }

public AdapterInfo(NetworkInterface adapter)
{
IPInterfaceProperties properties = adapter.GetIPProperties();
IPInterfaceStatistics statistics = adapter.GetIPStatistics();
Name = adapter.Description;
NetworkInterfaceType = adapter.NetworkInterfaceType;
Status = adapter.OperationalStatus;
DnsSuffix = properties.DnsSuffix;
Mtu = properties.GetIPv4Properties().Mtu;
DnsEnabled = properties.IsDnsEnabled;
IsDynamicDnsEnabled = properties.IsDynamicDnsEnabled;
IsReceiveOnly = adapter.IsReceiveOnly;
SupportsMulticast = adapter.SupportsMulticast;
Speed = adapter.Speed;
BytesReceived = statistics.BytesReceived;
BytesSent = statistics.BytesSent;
IncomingPacketsDiscarded = statistics.IncomingPacketsDiscarded;
IncomingPacketsWithErrors = statistics.IncomingPacketsWithErrors;
IncomingUnknownProtocolPackets = statistics.IncomingUnknownProtocolPackets;
NonUnicastPacketsReceived = statistics.NonUnicastPacketsReceived;
NonUnicastPacketsSent = statistics.NonUnicastPacketsSent;
OutgoingPacketsDiscarded = statistics.OutgoingPacketsDiscarded;
OutgoingPacketsWithErrors = statistics.OutgoingPacketsWithErrors;
OutputQueueLength = statistics.OutputQueueLength;
UnicastPacketsReceived = statistics.UnicastPacketsReceived;
UnicastPacketsSent = statistics.UnicastPacketsSent;
}
}
}

0 comments on commit b174b96

Please sign in to comment.