If you are in an organisation which covers everything under aliases but need to know those ips or hostnames I´ve built a little tool for this. I kept pinging the aliases and using nbtstat -A everyday to find this out and finally I lacked and made myself this little commandline tool for fixing it. The code is simple and you can download both solution and binaries below:
using System;
using System.Net;
namespace GetHostname {
class Program {
static void Main (string[] args) {
// Bool for wether or not the application should be "paused" before quitting
bool haltForKey = false;
// If we dont have any arguments from commandline
if (args.Length == 0) {
// Request user to input, exit if no input is given
Console.Write ("Enter alias or ip seperated by space: ");
var line = Console.ReadLine ();
if (string.IsNullOrEmpty (line))
return;
// Split all input values
args = line.Trim ().Split (' ');
// Mark that manual input has been given and as such halt before quitting
haltForKey = true;
}
// Print the results
Console.WriteLine ();
foreach (var entry in args)
Console.WriteLine (entry + ": " + FindHostName (entry));
// If user input was given halt execution before exiting
// (this is mainly for when debugging or executing outside command line window)
if (haltForKey)
Console.ReadKey ();
}
private static string FindHostName (string input) {
try {
// We don't know if we´ve got an alias or ip so get the host data so we can retrieve the IP
// it´s not actually neccessary but it saves us some complexity in code
var ipByInput = Dns.GetHostEntry (input);
// Then retrieve an entry by using the actual ip adress, this´ll give us the hostname which we return
var hostName = Dns.GetHostEntry (ipByInput.AddressList[0]);
return hostName.HostName;
} catch (Exception e) {
// Always catch any error, in this case we won't bother with stacktraces and somesuch
return "Failed to find hostname: " + e.Message;
}
}
}
}