MasterProgramCode:
// Obtain the IP address of the host domain name
Protected void btnshowlocal_click (Object sender, eventargs E)
{
Txtashowanswer. value = "";
String strshowany = string. empty;
String strhostname = DNS. gethostname (); // obtain the local host name
Strshowanwser = "the local host's name is:" + strhostname + "/N ";
Iphostentry iphost = DNS. gethostentry (strhostname); // resolve the host name to an iphostentry instance
Foreach (IPaddress IP in iphost. Addresslist) // resolve all IP addresses corresponding to the Host Name (domain name)
Strshowanwser + = "the local host's IP is:" + IP. tostring () + "/N ";
IPaddress localip = IPaddress. parse ("127.0.0.1"); // convert the string instance to an IP address
Ipendpoint ipep = new ipendpoint (localip, 80); // indicates the network endpoint as an IP address and port number.
Strshowanpoint + = "The ipendpoint is:" + ipep. tostring () + "/N ";
Strshowanwser + = "The address is:" + ipep. Address + "/N ";
Strshowanep + = "the port is:" + ipep. Port + "/N ";
Strshowanep + = "The addressfamily is:" + ipep. addressfamily + "/N ";
Strshowanwser + = "The Max port number is:" + ipendpoint. maxport + "/N ";
Strshowanport + = "the min port number is:" + ipendpoint. minport + "/N ";
Txtashowanswer. value = strshowaner;
}
Running result:
The local host's name is: Young
The local host's IP is: 1
The local host's IP is: 210.77.29.132
The ipendpoint is: 127.0.0.1: 80
The address is: 127.0.0.1
The port is: 80
The addressfamily is: Internetwork
The max port number is: 65535
The min port number is: 0