mirror of
https://github.com/Stone-Red-Code/ARP-Scanner.git
synced 2026-09-07 15:56:06 +02:00
Add humanizer library
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ArpLookup" Version="2.0.3" />
|
<PackageReference Include="ArpLookup" Version="2.0.3" />
|
||||||
<PackageReference Include="CuteUtils" Version="1.0.0" />
|
<PackageReference Include="CuteUtils" Version="1.0.0" />
|
||||||
|
<PackageReference Include="Humanizer" Version="2.14.1" />
|
||||||
<PackageReference Include="IPAddressRange" Version="6.0.0" />
|
<PackageReference Include="IPAddressRange" Version="6.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -45,18 +45,18 @@ internal partial class MacVendorLookup
|
|||||||
|
|
||||||
ConsoleExt.WriteLine("Downloading MAC database from maclookup.app...", ConsoleColor.DarkYellow);
|
ConsoleExt.WriteLine("Downloading MAC database from maclookup.app...", ConsoleColor.DarkYellow);
|
||||||
|
|
||||||
List<MacInformation>? newMacInformations = null;
|
List<MacInformation>? newMacInformation = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
newMacInformations = await httpClient.GetFromJsonAsync<List<MacInformation>>(macLookupUrl);
|
newMacInformation = await httpClient.GetFromJsonAsync<List<MacInformation>>(macLookupUrl);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
ConsoleExt.WriteLine($"Failed to download MAC database: {ex.Message}", ConsoleColor.Red);
|
ConsoleExt.WriteLine($"Failed to download MAC database: {ex.Message}", ConsoleColor.Red);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newMacInformations is null)
|
if (newMacInformation is null)
|
||||||
{
|
{
|
||||||
if (macDatabase.MacInformations.Count != 0)
|
if (macDatabase.MacInformations.Count != 0)
|
||||||
{
|
{
|
||||||
@@ -73,19 +73,19 @@ internal partial class MacVendorLookup
|
|||||||
|
|
||||||
_ = Directory.CreateDirectory(Path.GetDirectoryName(cachePath)!);
|
_ = Directory.CreateDirectory(Path.GetDirectoryName(cachePath)!);
|
||||||
|
|
||||||
macDatabase.MacInformations = newMacInformations;
|
macDatabase.MacInformations = newMacInformation;
|
||||||
macDatabase.LastUpdate = DateTime.Now;
|
macDatabase.LastUpdate = DateTime.Now;
|
||||||
File.WriteAllText(cachePath, JsonSerializer.Serialize(macDatabase));
|
File.WriteAllText(cachePath, JsonSerializer.Serialize(macDatabase));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MacInformation GetInformation(string macAdress)
|
public MacInformation GetInformation(string macAddress)
|
||||||
{
|
{
|
||||||
macAdress = macAdress.Replace("-", ":")[..8].ToUpper();
|
macAddress = macAddress.Replace("-", ":")[..8].ToUpper();
|
||||||
|
|
||||||
return macDatabase.MacInformations.Find(m => m.MacPrefix == macAdress) ?? new MacInformation()
|
return macDatabase.MacInformations.Find(m => m.MacPrefix == macAddress) ?? new MacInformation()
|
||||||
{
|
{
|
||||||
MacPrefix = macAdress,
|
MacPrefix = macAddress,
|
||||||
VendorName = "Unknown",
|
VendorName = "Unknown",
|
||||||
BlockType = "Unknown",
|
BlockType = "Unknown",
|
||||||
Private = null,
|
Private = null,
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
using CuteUtils.Misc;
|
using CuteUtils.Misc;
|
||||||
|
|
||||||
|
using Humanizer;
|
||||||
|
|
||||||
using NetTools;
|
using NetTools;
|
||||||
|
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
@@ -37,7 +39,11 @@ internal static class Program
|
|||||||
List<string> header = ["IP", "MAC"];
|
List<string> header = ["IP", "MAC"];
|
||||||
ConcurrentBag<string[]> activeHosts = [];
|
ConcurrentBag<string[]> activeHosts = [];
|
||||||
|
|
||||||
header.AddRange([nameof(MacInformation.VendorName), nameof(MacInformation.BlockType), nameof(MacInformation.Private), nameof(MacInformation.LastUpdate)]);
|
header.AddRange([
|
||||||
|
nameof(MacInformation.VendorName).Humanize(LetterCasing.Title),
|
||||||
|
nameof(MacInformation.BlockType).Humanize(LetterCasing.Title),
|
||||||
|
nameof(MacInformation.Private).Humanize(LetterCasing.Title),
|
||||||
|
nameof(MacInformation.LastUpdate).Humanize(LetterCasing.Title)]);
|
||||||
|
|
||||||
ConsoleExt.WriteLine("Starting scan...", ConsoleColor.DarkYellow);
|
ConsoleExt.WriteLine("Starting scan...", ConsoleColor.DarkYellow);
|
||||||
|
|
||||||
@@ -87,7 +93,7 @@ internal static class Program
|
|||||||
|
|
||||||
activeHostsTable.ToArray().To2D().PrintTable(TableStyle.List);
|
activeHostsTable.ToArray().To2D().PrintTable(TableStyle.List);
|
||||||
|
|
||||||
ConsoleExt.WriteLine($"{Environment.NewLine}Found {activeHosts.Count} active host{(activeHosts.Count == 1 ? "s" : "")}", ConsoleColor.Green);
|
ConsoleExt.WriteLine($"{Environment.NewLine}Found {"active host".ToQuantity(activeHosts.Count)}", ConsoleColor.Green);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user