This method is used to obtainIPAddress.IPThe address may beIPv4OrIPv6.GetHostAddressThe method is defined as follows:
PublicString getHostAddress ()
RegardlessInetAddressWhich method is used to create an object,GetHostAddressMethod will not be accessedDNSServer. If you want to accessIPv6Address remote host, which must be installed on the Operating SystemIPv6Protocol. Below isWindows 2003Install OnIPv6Procedure:
Step 1:Open"Local Connection"Properties dialog box. 1..
Figure 1 "Local Connection" attribute dialog box
Step 2:Click"Install"Button appears"Select network component type"Dialog box, select"Protocol"Click"Add"Button appears2Of"Select network protocol"Dialog box, select"Microsoft TCP/IPVersion6"And click"OK"Button.
Figure 2 "select Network Protocol" dialog box
In addition to the graphical interface for InstallationIPv6You can also use the following command line to installIPv6:
Netsh interface ipv6 install
The following codeDemonstrate how to useGetHostAddressGetIPv4AndIPv6Address, and how to obtain allIPAddress (includingIPv4AndIPv6Address ).
Package Mynet;
Import Java.net. * ;
Public Class MyIP
{
Public Static Void Main (String [] args) Throws Exception
{
// Output IPv4 address
InetAddress ipv4Address1 = InetAddress. getByName ( " 1.2.3.4 " );
System. out. println ( " Ipv4Address1: " + Ipv4Address1. getHostAddress ());
InetAddress ipv4Address2 = InetAddress. getByName ( " Www.ibm.com " );
System. out. println ( " Ipv4Address2: " + Ipv4Address2. getHostAddress ());
InetAddress ipv4Address3 = InetAddress. getByName ( " Myuniverse " );
System. out. println ( " Ipv4Address3: "