Obtain the host domain name and its IP address and port

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.