在java applet中如何获得本机的IP地址和机器名?(200分)

A

abc2002

Unregistered / Unconfirmed
GUEST, unregistred user!
我用Getlocalhost试了, 在appletviewer 和 netscape中能得到
但在IE中结果总是:localhost和127.0.0.1。
不知道怎样才能在IE得到正确的IP地址和机器名?
 
得到了有什么用吗?
 
BTW: 我也在学java. :)
 
呵呵, 试下用vj++重新编译, 然后在ie中运行.
 
你的开发环境是什么?
 
为何不用getHost和getPort调用远程主机的信息,调用本机的信息没有什么意义.
是吧?~_~
 
localhost=127.0.0.1是系统定义的
在windows目录下的hosts.sam文件中
实际上applet可能无法得到本机的ip
(安全性),你可以用active x 实现
 
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);
}
}
 
取不到的.可以用javascript取到后,再传入applet
 
xwolf的程序我试过的,完全可以的。。。
 
xwolf的程序我也行哦@@....
 
>>在java applet中如何获得本机的IP地址和机器名?
你们在applet下用ie试过吗?人家提问的很清楚,是applet,不是application
 
myaddress=java.net.inetaddress.getlocalhost();
myaddress2=java.net.inetaddress.getlocalhost();
host=myaddress.gethostname();
ip=myaddress2.gethostaddress();
 
接受答案了.
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
933
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
顶部