Skip to content

Commit

Permalink
Merging fixes to master (#14)
Browse files Browse the repository at this point in the history
* Reorganized project, started implementing user config

* Removed obselete code

* Restored interface, created config utility, extracted some common operations and updated readme.

* Updated template config for examples

* Added config loader and converter for consumption in app

* Refactored code, added config/logic for custom IP list

* Refactored config classes, fixed bug with subnet mask

* Updated readme for new property

* Added window sizing specifically for Windows systems

* Updated issue with interface selection

* Fixing linux bug

* Fixing issues with Linux scanning
  • Loading branch information
0xrgg authored Feb 26, 2023
1 parent 9c49462 commit 0e642ba
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
13 changes: 12 additions & 1 deletion Common/Config/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ public class Config
public static IEnumerable<string> CUSTOM_IP_ADDRESSES { get; set; }

public static List<ConfigSetting> ConfigSettings { get; set; }
public static bool WIN_HOST_OS { get; set; }

public static void BuildConfig()
{
if (System.Runtime.InteropServices.RuntimeInformation.OSDescription.Contains("Windows"))
WIN_HOST_OS = GetOS();

if (WIN_HOST_OS)
{
// Windows only
Console.SetWindowSize(120, 30);
Expand Down Expand Up @@ -63,6 +66,14 @@ public static void BuildConfig()
ConfigSettings.Clear();
}

public static bool GetOS()
{
if (System.Runtime.InteropServices.RuntimeInformation.OSDescription.Contains("Windows"))
return true;

return false;
}

public static void LoadMACList()
{
MAC_LIST = CommonOperations.LoadListFromFile(Config.MAC_LIST_PATH);
Expand Down
2 changes: 1 addition & 1 deletion Netscan/ArpScan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private static Host LookupMAC(string ipString, Host result)
{
PhysicalAddress mac = Arp.Lookup(IPAddress.Parse(ipString));

if (mac is not null)
if (mac is not null && mac.ToString() is not "000000000000")
{
var paddedMAC = PadMACString(mac?.ToString());

Expand Down
2 changes: 1 addition & 1 deletion Radar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public bool ValidateInput(string input, int interfaceCount)
{
if (int.TryParse(input, out var parsedInput))
{
if (parsedInput < interfaceCount)
if (parsedInput - 1 < interfaceCount && parsedInput - 1 > -1)
return true;

return false;
Expand Down
9 changes: 5 additions & 4 deletions Services/NetworkScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public IEnumerable<Host> ScanNetwork(IPAddress ipAddress, string subnetMask)

stopWatch.Stop();

var elapsedTime = FormatStopwatch(stopWatch);
var elapsedTime = FormatStopwatch();

CommonConsole.WriteToConsole($"Found {ActiveHosts.Count()} hosts...", ConsoleColor.Yellow);
CommonConsole.WriteToConsole($"Scan completed in: {elapsedTime}", ConsoleColor.Green);
Expand Down Expand Up @@ -242,17 +242,18 @@ public bool PingHost(IPAddress targetIp)

host = ArpScan.Scan(targetIp.ToString());

if (host.IP is not null)
if (host.MAC is not null)
{
CommonConsole.WriteToConsole($"Found host: {host.IP}", ConsoleColor.Green);
host.HostName = QueryDNS(host).HostName ?? "Unknown";
ActiveHosts.Add(host);
return true;
}

return true;
return false;
}

private string FormatStopwatch(Stopwatch stopwatch)
private string FormatStopwatch()
{
TimeSpan ts = stopWatch.Elapsed;

Expand Down

0 comments on commit 0e642ba

Please sign in to comment.