Java Network Programming 1-Querying Internet addresses

Source: Internet
Author: User

After the DNS query results are cached, the successful result is permanently cached, the failure result is cached 10s, the following method to set the success and failure of the cache time
//0 is not cached,-1 is never expired, other units are S
Security.setproperty ("Networkaddress.cache.ttl", "10");
Security.setproperty ("Networkaddress.cache.negative.ttl", "3");


//If an IP address is passed in, no DNS query is made
InetAddress address=inetaddress.getbyname ("www.baidu.com");
//inetaddress.getbyname () Incoming IP address, and then call GetHostName () will not be abnormal because of query DNS failure
System.out.println (Address.gethostname ()); //www.baidu.com
System.out.println (Address.gethostaddress ()); //180.97.33.107
System.out.println (Arrays.tostring (Address.getaddress ())); //[-76, 107]
System.out.println (Address.tostring ()); //www.baidu.com/180.97.33.107


Equals () Having the same IP address is equal; Hashcode () calculated based on IP address

System.out.println (Address.equals (address2));
System.out.println (Address.hashcode ());


//test whether the machine is accessible via the Echo port
Address.isreachable (1000);


//Get information about the hardware network Port
NetworkInterface inter=networkinterface.getbyname ("Eth3");
System.out.println (Inter.getdisplayname ());
System.out.println (Inter.getname ());

Java Network Programming 1-Querying Internet addresses

Related Article

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.