Skip to content

Commit

Permalink
GetNetworkInterfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
FuzzySecurity committed Sep 25, 2020
1 parent 993c425 commit c12c281
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 0 deletions.
25 changes: 25 additions & 0 deletions GetNetworkInterfaces/GetNetworkInterfaces.sln
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
6 changes: 6 additions & 0 deletions GetNetworkInterfaces/GetNetworkInterfaces/App.config
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>
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>
123 changes: 123 additions & 0 deletions GetNetworkInterfaces/GetNetworkInterfaces/Program.cs
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();
}
}
}
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")]
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -612,3 612,34 @@ C:\> SystemProcessAndThreadsInformation.exe -p 4508
[...Snipped...]
```

### GetNetworkInterfaces

GetNetworkInterfaces is a small .Net45 utility to pull local network adapter information. It mostly has feature parity with "ipconfig /all" and can be useful for some fast enumeration.

```
C:\> GetNetworkInterfaces.exe
[...Snipped...]
VMware Virtual Ethernet Adapter for VMnet8
Name .................................... : VMware Network Adapter VMnet8
Interface type .......................... : Ethernet
Physical Address ........................ : 005056C00008
Operational status ...................... : Up
IP version .............................. : IPv4 IPv6
IPv6 .................................... : fe80::2101:9102:751a:fdd2
IPv4 .................................... : 192.168.199.1
Mask .................................... : 255.255.255.0
DHCP .................................... : True
DHCP Server ............................. : 192.168.199.254
DNS Server .............................. : fec0:0:0:ffff::1%1
DNS Server .............................. : fec0:0:0:ffff::2%1
DNS Server .............................. : fec0:0:0:ffff::3%1
Dynamic DNS ............................. : True
DNS suffix .............................. :
DNS enabled ............................. : False
Primary WINS Server ..................... : 192.168.199.2
[...Snipped...]
```

0 comments on commit c12c281

Please sign in to comment.