Java Socket Learning (1)

Source: Internet
Author: User
Import java.net. inet4address; import java.net. inet6address; import java.net. inetaddress; import java.net. networkinterface; import Java. util. enumeration;/*** socket learning ** @ author administrator **/public class inteaddressexample {public static void main (string [] ARGs) {// network interface and related address information of the active host try {enumeration <networkinterface> interfacelist = networkinterface. getnetworkinterfaces (); If (interfacelist = NULL) {System. out. println ("no interface found");} else {While (interfacelist. hasmoreelements () {networkinterface iface = interfacelist. nextelement (); // getname () returns the local interface. The local name of the interface is usually composed of letters and numbers. out. println ("Interface Name:" + iface. getname () + ":"); enumeration <inetaddress> addrlist = iface. getinetaddresses (); If (! Addrlist. hasmoreelements () {system. out. println ("\ t (corresponding address not found under this interface)");} while (addrlist. hasmoreelements () {inetaddress address = addrlist. nextelement (); system. out. println ("\ taddress" + (address instanceof inet4address? "(V4)": (address instanceof inet6address? "(V6 )":"(?) "); System. out. println (":" + address. gethostaddress () ;}}} catch (exception e) {e. printstacktrace () ;}// obtain the host name and address for each parameter input by the command line for (string HOST: ARGs) {try {system. out. println (host + ":"); inetaddress [] Addresslist = inetaddress. getallbyname (host); For (inetaddress Address: Addresslist) {system. out. println ("\ t" + address. gethostaddress () + "/" + address. gethostaddress () ;}} catch (exception e) {e. printstacktrace ();}}}}

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.