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; } } } }
HI HOW TO RUN THIS CODE PLS
Hi,
Certainly, should´ve added some kind of description, sorry 🙂
The code is bundled in a Visual Studio 2012 project/solution so you would need that to open it at all but I supplied a compiled binary aswell (simple .exe) which is placed in the GetHostnameindebug -folder by the name GetHostname.exe
To use the program simply run commandline “GetHostname youralias.com”. A word of warning however, I´ve found that some dns-entries isn’t returned correctly so if the hostname seems totally of it probably is.