Current location - Quotes Website - Collection of slogans - How to get the real ip and port number of the client in java
How to get the real ip and port number of the client in java
Public static string getHostIpAddress() {

String hostIp =

inet address net address = getine address();

hostIp = getHostIp(net address);

Return to hostIp

}

public static inet address getinet address(){

Try {

Returns inetaddress. getlocalhost ();

} catch (UnknownHostException e) {

System.out.println ("Unknown host!" );

}

Returns null

}

Public static string gethostip (inetaddress netaddress) (

if (null == netAddress) {

Returns null

}

string IP = net address . gethostaddress(); //get the ip address

Return to IP;

}

Public static string gethostname (inetaddress netaddress) (

if (null == netAddress) {

Returns null

}

string name = net address . get hostname(); //Get the host address

Returns the name;

}