Question: Need Help with C# Please! Based on the programs given in the lab, use a text editor (e.g., Notepad or Notepad++) to create a C#
Need Help with C# Please!
Based on the programs given in the lab, use a text editor (e.g., Notepad or Notepad++) to create a C# program named ShowHostNameOfIP.cs to satisfy the following:
1. After compilation, user can run it on command line with no input data values after the command.
2. When it runs, it prompts "Enter an IP address (e.g., 131.247.2.211): " to ask user to enter an IP address at command line. To simplify the program code, it assumes only valid and existing IP address is entered, meaning, there is no need to test if the input IP address is valid or not. *In this case, if an invalid IP address is entered, the program would fail and we ignore it.
3. After reading the given IP address, it prints on screen a message "Host name of x.x.x.x is: hhhhhh", where 'x.x.x.x' is the IP address and 'hhhhhh' is the host name it finds of the IP.
To complete this program, it may require a little research in the area of C# socket programming.
For instance, you learn that Dns class has GetHostName() and GetHostAddresses() methods to retrieve the local host name and its IP addresses. It also has other methods such as GetHostEntry(x) that can help the work here. However, two things we need to take care to make this method work.
First, the above x is supposed to be an IP address and it must be an IPAddress object. Because user of this program only enters an IP address from keyboard, this input is only a string value, not an IPAddress object. In other words, what user entered cannot be used as an input IPAddress object to this method. To turn the given string into a real IPAddress object, it must be parsed by the Parse() method of IPAddress class. Once you have this IPAddress object, it can be used as the input to GetHostEntry().
Second, if you get the documentation (Links to an external site.)regarding the GetHostEntry method, you should know it does not return the host name directly and we cannot display it as the host name to user. Instead, this method returns an IPHostEntry object. The documentation (Links to an external site.)of IPHostEntry tells us that every IPHostEntry object has a property HostName which returns the host name as a string and that is what we need to display to user.
Research and study of these documentations take time. So, please plan with enough time to work on this assignment before due.
No syntax errors please.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
