Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In a C# program, take an IPv4 address provided by the user, and return the hostn

ID: 3870861 • Letter: I

Question

In a C# program, take an IPv4 address provided by the user, and return the hostname for that IPv4 address. I have come a decent way but my code will only return: System.Net.IPHostEntry. Here is a copy of my code:

string ip;

Console.WriteLine("Please enter an IPv4 address: ");

ip = Console.ReadLine();

IPAddress address = IPAddress.Parse(ip);

IPHostEntry hostInfo = Dns.GetHostEntry(address);   

Console.WriteLine(hostInfo);

Like I said, I need the code to essential accept an IP address and return the hostname for that address. So if the user enters: 74.125.136.102, the program should display: google.com.

Explanation / Answer

You can try this:

IPHostEntry hostEntry = Dns.GetHostEntry(ipaddress);
Console.WriteLine("DNS name : " + hostEntry.HostName);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote