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
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);
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
