api什么的都没有答案// 文件名为 NetTool.java (注意:在JAVA 语言中大小写敏感)
import java.net.*;
public class NetTool{
InetAddress myIPaddress=null;
InetAddress myServer=null;public static void main( String args[]){ NetTool mytool;
mytool=new NetTool(); System.out.println("Your host IP is: " + mytool.getMyIP());
System.out.println("The Server IP is :" +mytool.getServerIP());}//取得LOCALHOST的IP地址
public InetAddress getMyIP() {
try { myIPaddress=InetAddress.getLocalHost();}
catch (UnknownHostException e) {}
return (myIPaddress);
}
//取得 www.abc.com 的IP地址
public InetAddress getServerIP(){
try {myServer=InetAddress.getByName("www.abc.com");}
catch (UnknownHostException e) {}
return (myServer);
}} public class catchserverip{
InetAddress ServerIPaddress=null;
//取得Server的IP地址
public InetAddress getServerIP() {
try { ServerIPaddress=InetAddress.getLocalHost();}
catch (UnknownHostException e) {}
return (ServerIPaddress);
}
}
/**
* Creates a socket and connects it to the specified remote address on
* the specified remote port. The Socket will also bind() to the local
* address and port supplied.
* <p>
* If there is a security manager, its
* <code>checkConnect</code> method is called
* with the host address and <code>port</code>
* as its arguments. This could result in a SecurityException.
*
* @param address the remote address
* @param port the remote port
* @param localAddr the local address the socket is bound to
* @param localPort the local port the socket is bound to
* @exception IOException if an I/O error occurs when creating the socket.
* @exception SecurityException if a security manager exists and its
* <code>checkConnect</code> method doesn't allow the operation.
* @see SecurityManager#checkConnect
* @since JDK1.1
*/
public Socket(InetAddress address, int port, InetAddress localAddr,
int localPort) throws IOException {
this(address != null ? new InetSocketAddress(address, port) : null,
new InetSocketAddress(localAddr, localPort), true);
}
String userIP=request.getRemoteAddr();可以得到本地IP
String userIP=request.getRemoteHost();可以得到服务器的机器名
import java.net.*;
public class NetTool{
InetAddress myIPaddress=null;
InetAddress myServer=null;public static void main( String args[]){ NetTool mytool;
mytool=new NetTool(); System.out.println("Your host IP is: " + mytool.getMyIP());
System.out.println("The Server IP is :" +mytool.getServerIP());}//取得LOCALHOST的IP地址
public InetAddress getMyIP() {
try { myIPaddress=InetAddress.getLocalHost();}
catch (UnknownHostException e) {}
return (myIPaddress);
}
//取得 www.abc.com 的IP地址
public InetAddress getServerIP(){
try {myServer=InetAddress.getByName("www.abc.com");}
catch (UnknownHostException e) {}
return (myServer);
}} public class catchserverip{
InetAddress ServerIPaddress=null;
//取得Server的IP地址
public InetAddress getServerIP() {
try { ServerIPaddress=InetAddress.getLocalHost();}
catch (UnknownHostException e) {}
return (ServerIPaddress);
}
}
/**
* Creates a socket and connects it to the specified remote address on
* the specified remote port. The Socket will also bind() to the local
* address and port supplied.
* <p>
* If there is a security manager, its
* <code>checkConnect</code> method is called
* with the host address and <code>port</code>
* as its arguments. This could result in a SecurityException.
*
* @param address the remote address
* @param port the remote port
* @param localAddr the local address the socket is bound to
* @param localPort the local port the socket is bound to
* @exception IOException if an I/O error occurs when creating the socket.
* @exception SecurityException if a security manager exists and its
* <code>checkConnect</code> method doesn't allow the operation.
* @see SecurityManager#checkConnect
* @since JDK1.1
*/
public Socket(InetAddress address, int port, InetAddress localAddr,
int localPort) throws IOException {
this(address != null ? new InetSocketAddress(address, port) : null,
new InetSocketAddress(localAddr, localPort), true);
}
String userIP=request.getRemoteAddr();可以得到本地IP
String userIP=request.getRemoteHost();可以得到服务器的机器名
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货