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

Based on the programs given in the lab, use a text editor to create a C# program

ID: 3886693 • Letter: B

Question

Based on the programs given in the lab, use a text editor to create a C# program named “ShowHostNameOfIP.cs” to satisfy the following:

1. After compilation, user can run it on command line without input data values after the command.

2. When it runs, it prompts "Enter an IP address (e.g., 131.247.2.211): " to let user enter an IP address at command line. To simplify the program code, it assumes only valid and existing IP address is entered, meaning, it does not test if the input IP address is valid or not. *In case of an invalid IP address, the program could fail.

3. It reads the above entered IP address and prints on screen a message "Host name of x.x.x.x is: hhhhhh", where 'x.x.x.x' is the entered IP address and 'hhhhhh' is the host name of the IP it finds.

This program works very similarly to the 3rd example program of the lab, including its total file size. However, to complete this program, it may require a little more research in the area of C# socket programming. So, please plan with enough time to work on this assignment before due.

Only the completed source file ShowHostNameOfIP.cs needs to submit.

this is 3rd example:

Based on the programs given in the lab, use a text editor to create a C# program named “ShowHostNameOfIP.cs” to satisfy the following:

1. After compilation, user can run it on command line without input data values after the command.

2. When it runs, it prompts "Enter an IP address (e.g., 131.247.2.211): " to let user enter an IP address at command line. To simplify the program code, it assumes only valid and existing IP address is entered, meaning, it does not test if the input IP address is valid or not. *In case of an invalid IP address, the program could fail.

3. It reads the above entered IP address and prints on screen a message "Host name of x.x.x.x is: hhhhhh", where 'x.x.x.x' is the entered IP address and 'hhhhhh' is the host name of the IP it finds.

This program works very similarly to the 3rd example program of the lab, including its total file size. However, to complete this program, it may require a little more research in the area of C# socket programming. So, please plan with enough time to work on this assignment before due.

Only the completed source file ShowHostNameOfIP.cs needs to submit.

this is 3rd example:

/*

* This is a C# Program which displays the IP address of an input URL.

*/

using System;

using System.Net;

namespace CNT4704L

{

class MySocketLab

{

static void Main()

{

String strSiteName, ipv4_or_ipv6;

Console.Write("Enter a site name (e.g., www.usf.edu): ");

strSiteName = Console.ReadLine();

IPAddress addr = Dns.GetHostAddresses(strSiteName)[0];

Console.Write(" IP address of {0} is: ", strSiteName);

ipv4_or_ipv6 = addr.GetAddressBytes().Length == 4 ? "IPv4" : "IPv6"; //IPv4 is 4 bytes, IPv6 is 16 bytes

Console.WriteLine("({0}) {1}", ipv4_or_ipv6, addr);

}

}

}

Explanation / Answer

below ius your program :-

using System;
using System.Net;
using System.Net.Sockets;

namespace Lab
{
class ShowHostNameOfIP
{
static void Main()
{
Console.Write("Enter an IP address (e.g., 131.247.2.211): ");
String addr = Console.ReadLine();
try {
IPHostEntry name = Dns.GetHostEntry(addr);

Console.WriteLine(" Host name of {0} is: {1}", addr, name.HostName);
}
catch(SocketException e) {
Console.WriteLine(" Some issue in Network currently. We are unable to resolve 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