-
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
993c425
commit c12c281
Showing
6 changed files
with
274 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.30503.244 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetNetworkInterfaces", "GetNetworkInterfaces\GetNetworkInterfaces.csproj", "{467EE2A9-2F01-4A71-9647-2A2D9C31E608}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{467EE2A9-2F01-4A71-9647-2A2D9C31E608}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{467EE2A9-2F01-4A71-9647-2A2D9C31E608}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{467EE2A9-2F01-4A71-9647-2A2D9C31E608}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{467EE2A9-2F01-4A71-9647-2A2D9C31E608}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {FAA8DE8D-DFCF-4D7A-98E6-243B239556C8} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
|
||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup> | ||
</configuration> |
53 changes: 53 additions & 0 deletions
53
GetNetworkInterfaces/GetNetworkInterfaces/GetNetworkInterfaces.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,53 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{467EE2A9-2F01-4A71-9647-2A2D9C31E608}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>GetNetworkInterfaces</RootNamespace> | ||
<AssemblyName>GetNetworkInterfaces</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<Deterministic>true</Deterministic> | ||
<TargetFrameworkProfile /> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<Prefer32Bit>false</Prefer32Bit> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<Prefer32Bit>false</Prefer32Bit> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,123 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.NetworkInformation; | ||
|
||
namespace GetNetworkInterfaces | ||
{ | ||
class Program | ||
{ | ||
public static void GetMyInterfaces() | ||
{ | ||
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); | ||
foreach (NetworkInterface adapter in adapters) | ||
{ | ||
IPInterfaceProperties properties = adapter.GetIPProperties(); | ||
Console.WriteLine("\n" adapter.Description); | ||
Console.WriteLine(" Name .................................... : {0}", adapter.Name); | ||
Console.WriteLine(" Interface type .......................... : {0}", adapter.NetworkInterfaceType); | ||
Console.WriteLine(" Physical Address ........................ : {0}", adapter.GetPhysicalAddress().ToString()); | ||
Console.WriteLine(" Operational status ...................... : {0}", adapter.OperationalStatus); | ||
|
||
string versions = ""; | ||
if (adapter.Supports(NetworkInterfaceComponent.IPv4)) | ||
{ | ||
versions = "IPv4"; | ||
} | ||
if (adapter.Supports(NetworkInterfaceComponent.IPv6)) | ||
{ | ||
if (versions.Length > 0) | ||
{ | ||
versions = " "; | ||
} | ||
versions = "IPv6"; | ||
} | ||
Console.WriteLine(" IP version .............................. : {0}", versions); | ||
|
||
// Get IP | ||
foreach (UnicastIPAddressInformation ip in adapter.GetIPProperties().UnicastAddresses) | ||
{ | ||
if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) | ||
{ | ||
Console.WriteLine(" IPv4 .................................... : {0}", ip.Address.ToString()); | ||
Console.WriteLine(" Mask .................................... : {0}", ip.IPv4Mask); | ||
IPv4InterfaceProperties iProp = adapter.GetIPProperties().GetIPv4Properties(); | ||
try | ||
{ | ||
Console.WriteLine(" DHCP .................................... : {0}", iProp.IsDhcpEnabled); | ||
} catch { } | ||
} | ||
|
||
if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) | ||
{ | ||
Console.WriteLine(" IPv6 .................................... : {0}", ip.Address.ToString()); | ||
} | ||
} | ||
|
||
IPInterfaceProperties iip = adapter.GetIPProperties(); | ||
GatewayIPAddressInformationCollection giaic = iip.GatewayAddresses; | ||
if (giaic.Count > 0) { | ||
if (giaic.First().Address.AddressFamily.ToString() == "InterNetwork") | ||
{ | ||
Console.WriteLine(" Default Gateway ......................... : {0}", giaic.First().Address); | ||
} | ||
} | ||
|
||
IPAddressCollection iac = adapter.GetIPProperties().DhcpServerAddresses; | ||
if (iac.Count > 0) | ||
{ | ||
foreach (IPAddress ia in iac) | ||
{ | ||
if (ia.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) | ||
{ | ||
Console.WriteLine(" DHCP Server ............................. : {0}", ia.MapToIPv4().ToString()); | ||
} | ||
|
||
if (ia.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) | ||
{ | ||
Console.WriteLine(" DHCP Server ............................. : {0}", ia.MapToIPv6().ToString()); | ||
} | ||
} | ||
} | ||
|
||
IPAddressCollection iacd = adapter.GetIPProperties().DnsAddresses; | ||
if (iacd.Count > 0) | ||
{ | ||
foreach (IPAddress ia in iacd) | ||
{ | ||
if (ia.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) | ||
{ | ||
Console.WriteLine(" DNS Server .............................. : {0}", ia.MapToIPv4().ToString()); | ||
} | ||
|
||
if (ia.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) | ||
{ | ||
Console.WriteLine(" DNS Server .............................. : {0}", ia.MapToIPv6().ToString()); | ||
} | ||
} | ||
} | ||
Console.WriteLine(" Dynamic DNS ............................. : {0}", iip.IsDynamicDnsEnabled); | ||
Console.WriteLine(" DNS suffix .............................. : {0}", properties.DnsSuffix); | ||
Console.WriteLine(" DNS enabled ............................. : {0}", properties.IsDnsEnabled); | ||
|
||
if (adapter.Supports(NetworkInterfaceComponent.IPv4)) | ||
{ | ||
IPv4InterfaceProperties ipv4 = properties.GetIPv4Properties(); | ||
if (ipv4.UsesWins) | ||
{ | ||
IPAddressCollection winsServers = properties.WinsServersAddresses; | ||
if (winsServers.Count > 0) | ||
{ | ||
Console.WriteLine(" Primary WINS Server ..................... : {0}", winsServers.First().MapToIPv4().ToString()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
static void Main(string[] args) | ||
{ | ||
GetMyInterfaces(); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
GetNetworkInterfaces/GetNetworkInterfaces/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("GetNetworkInterfaces")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("GetNetworkInterfaces")] | ||
[assembly: AssemblyCopyright("Copyright © 2020")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("467ee2a9-2f01-4a71-9647-2a2d9c31e608")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters