如何用Javascript获得IP地址(200分)

  • 主题发起人 主题发起人 iwantoknow
  • 开始时间 开始时间
I

iwantoknow

Unregistered / Unconfirmed
GUEST, unregistred user!
我想编写一个网页,不知如何利用JSP获得点击者的IP地址,从而采取相应处理!谢谢
 
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);
}
}
 
request.getRemoteAddr()
 
后退
顶部