mirror of
https://github.com/Stone-Red-Code/ARP-Scanner.git
synced 2026-09-04 08:56:04 +02:00
Add chocolatey and snapcraft packages
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.31912.275
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ARP-Scanner", "ARP-Scanner\ARP-Scanner.csproj", "{1616AA27-AEE0-48BD-8086-DB0B955BE42B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{1616AA27-AEE0-48BD-8086-DB0B955BE42B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1616AA27-AEE0-48BD-8086-DB0B955BE42B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1616AA27-AEE0-48BD-8086-DB0B955BE42B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1616AA27-AEE0-48BD-8086-DB0B955BE42B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {E6B80167-71E0-4048-BFE6-61DCBA463D87}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>ARP_Scanner</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ArpLookup" Version="2.0.3" />
|
||||
<PackageReference Include="IPAddressRange" Version="5.0.0" />
|
||||
<PackageReference Include="Stone_Red-C-Sharp-Utilities" Version="1.0.3.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="mac-vendors.csv">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,57 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace ARP_Scanner;
|
||||
|
||||
internal class MacVendorLookup
|
||||
{
|
||||
public readonly string[] header;
|
||||
private readonly string[][] fields;
|
||||
|
||||
public MacVendorLookup(string csvPath)
|
||||
{
|
||||
if (!File.Exists(csvPath))
|
||||
{
|
||||
header = Array.Empty<string>();
|
||||
fields = Array.Empty<string[]>();
|
||||
return;
|
||||
}
|
||||
|
||||
string[] lines = File.ReadAllLines(csvPath);
|
||||
|
||||
header = lines[0].Split(',');
|
||||
fields = lines.Skip(1).Select(l => Regex.Split(l, ",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))")).ToArray();
|
||||
}
|
||||
|
||||
public string[] GetInformation(string macAdress)
|
||||
{
|
||||
string[]? data = fields.FirstOrDefault(f => macAdress.StartsWith(f[0]))?.ToArray();
|
||||
|
||||
if (fields.Length == 0 || header.Length == 0)
|
||||
{
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
else if (data is null)
|
||||
{
|
||||
string[] result = new string[header.Length - 1];
|
||||
for (int i = 0; i < result.Length; i++)
|
||||
{
|
||||
result[i] = "Unknown";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
for (int i = 1; i < header.Length; i++)
|
||||
{
|
||||
result.Add($"{data[i]}");
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public string[] GetHeader()
|
||||
{
|
||||
return header!.Skip(1).ToArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
using ArpLookup;
|
||||
|
||||
using NetTools;
|
||||
|
||||
using Stone_Red_Utilities.CollectionExtentions;
|
||||
using Stone_Red_Utilities.ConsoleExtentions;
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
|
||||
namespace ARP_Scanner;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
private static async Task Main(string[] args)
|
||||
{
|
||||
bool success = false;
|
||||
IPAddress[]? ipAddresses = null;
|
||||
MacVendorLookup macVendorLookup = new MacVendorLookup("mac-vendors.csv");
|
||||
|
||||
if (!Arp.IsSupported)
|
||||
{
|
||||
ConsoleExt.WriteLine("ARP is not supported on this platform!", ConsoleColor.Red);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Length >= 1)
|
||||
{
|
||||
success = IPAddressRange.TryParse(string.Join("", args), out IPAddressRange iPAddressRange);
|
||||
ipAddresses = iPAddressRange.AsEnumerable().ToArray();
|
||||
}
|
||||
|
||||
if (!success || ipAddresses is null)
|
||||
{
|
||||
ConsoleExt.WriteLine("Invalid IP range!", ConsoleColor.Red);
|
||||
return;
|
||||
}
|
||||
|
||||
int ipAddressesCount = ipAddresses.Length;
|
||||
int processedIpAddressesCount = 0;
|
||||
|
||||
List<string> header = new List<string>() { "IP", "MAC" };
|
||||
ConcurrentBag<string[]> activeHosts = new ConcurrentBag<string[]>();
|
||||
|
||||
header.AddRange(macVendorLookup.GetHeader());
|
||||
|
||||
ConsoleExt.WriteLine("Starting scan...", ConsoleColor.DarkYellow);
|
||||
|
||||
await Parallel.ForEachAsync(ipAddresses, async (ipAddress, _) =>
|
||||
{
|
||||
PhysicalAddress? mac = await Arp.LookupAsync(ipAddress);
|
||||
|
||||
int localProcessedIpAddressesCount = Interlocked.Increment(ref processedIpAddressesCount);
|
||||
if (mac is not null)
|
||||
{
|
||||
string formattedMac = BitConverter.ToString(mac.GetAddressBytes());
|
||||
|
||||
List<string> info = new List<string> { ipAddress.ToString(), formattedMac };
|
||||
info.AddRange(macVendorLookup.GetInformation(formattedMac));
|
||||
ConsoleExt.WriteLine($"Progress: {localProcessedIpAddressesCount}/{ipAddressesCount} [{100d / ipAddressesCount * localProcessedIpAddressesCount:0.00}%] | Active: {ipAddress}", ConsoleColor.Green);
|
||||
activeHosts.Add(info.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleExt.WriteLine($"Progress: {localProcessedIpAddressesCount}/{ipAddressesCount} [{100d / ipAddressesCount * localProcessedIpAddressesCount:0.00}%] | Inactive: {ipAddress}", ConsoleColor.Red);
|
||||
}
|
||||
});
|
||||
|
||||
if (!activeHosts.IsEmpty)
|
||||
{
|
||||
Console.WriteLine(Environment.NewLine + "Active hosts:");
|
||||
|
||||
List<string[]>? activeHostsTable = activeHosts.ToList();
|
||||
|
||||
activeHostsTable.Insert(0, header.ToArray());
|
||||
|
||||
To2D(activeHostsTable.ToArray()).PrintTable(TableStyle.List);
|
||||
|
||||
ConsoleExt.WriteLine($"{Environment.NewLine}Found {activeHosts.Count} active hosts", ConsoleColor.Green);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleExt.WriteLine($"{Environment.NewLine}No active hosts found", ConsoleColor.Red);
|
||||
}
|
||||
}
|
||||
|
||||
private static T[,] To2D<T>(T[][] source)
|
||||
{
|
||||
try
|
||||
{
|
||||
int FirstDim = source.Length;
|
||||
int SecondDim = source.GroupBy(row => row.Length).Single().Key; // throws InvalidOperationException if source is not rectangular
|
||||
|
||||
T[,]? result = new T[FirstDim, SecondDim];
|
||||
for (int i = 0; i < FirstDim; ++i)
|
||||
{
|
||||
for (int j = 0; j < SecondDim; ++j)
|
||||
{
|
||||
result[i, j] = source[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
throw new InvalidOperationException("The given jagged array is not rectangular.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"profiles": {
|
||||
"ARP-Scanner": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "192.168.1.0 - 192.168.1.255"
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user