Skip to content

Commit

Permalink
display hostnames
Browse files Browse the repository at this point in the history
  • Loading branch information
Elias Ruemmler committed Jan 9, 2019
1 parent b787146 commit dd6d14d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*.user
*.userosscache
*.sln.docstates
private/

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
Expand Down
34 changes: 24 additions & 10 deletions NetworkScanner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,28 @@ static class Scanner
public static void Main(string[] args)
{
#region Startup

var versionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location);
var attribute = Assembly.GetExecutingAssembly()
.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false)
.Cast<AssemblyDescriptionAttribute>().FirstOrDefault();
var appName = string.Format("{0} v{1}", typeof(Scanner).Assembly.GetName().Name, versionInfo.ProductVersion);

Console.Title = appName;
Console.WindowWidth = 80;
Console.BufferWidth = 80;
Console.WindowHeight = 36;


Console.WriteLine();
Console.BackgroundColor = ConsoleColor.Gray;
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine("{0} v{1}", typeof(Scanner).Assembly.GetName().Name, versionInfo.ProductVersion);
Console.WriteLine(appName);
Console.ResetColor();
if (attribute != null)
Console.WriteLine(attribute.Description);
Console.WriteLine();
Console.WriteLine(versionInfo.LegalCopyright);
Console.WriteLine(String.Empty.PadLeft(80, '-'));
Console.WriteLine();

#endregion
string baseIP = null;
Expand Down Expand Up @@ -80,7 +85,6 @@ public static void Main(string[] args)

Console.WriteLine();
Console.WriteLine(String.Empty.PadLeft(80, '-'));
Console.WriteLine();
}


Expand All @@ -101,11 +105,11 @@ public static void Main(string[] args)
{
lock (@lock)
{
m_Instances += 1;
m_Instances++;
}

p.SendAsync(string.Concat(baseIP, cnt.ToString()), m_Timeout, data, pingOptions);
cnt += 1;
cnt++;
}

while (m_Instances > 0)
Expand Down Expand Up @@ -167,18 +171,28 @@ public static IPAddress GetIPv4Address(IPInterfaceProperties adapterProperties)
return null;
}

public static void PingCompleted(object s, PingCompletedEventArgs e)
public static String GetHostNameByIp(IPAddress address)
{
lock (@lock)
try
{
m_Instances -= 1;
return Dns.GetHostEntry(address).HostName;
}
catch (System.Net.Sockets.SocketException ex)
{
return String.Empty;
}
}

public static void PingCompleted(object s, PingCompletedEventArgs e)
{
if (e.Reply.Status == IPStatus.Success)
{
Console.WriteLine(string.Concat("Active IP: ", e.Reply.Address.ToString()));
Console.WriteLine("Active IP: {0,-16} {1}", e.Reply.Address, GetHostNameByIp(e.Reply.Address));
m_Result += 1;
}

lock (@lock)
m_Instances--;
}


Expand Down
Binary file modified docs/NetworkScanner_Screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dd6d14d

Please sign in to comment.