高分求高手:jsp中如何获得服务器的网卡地址?

bnuaming 2003-09-12 06:06:29
怎样利用java获得服务器的网卡地址?最好能跨平台,希望高手不吝赐教,给出源码......
...全文
100 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
seawhl 2003-09-12
  • 打赏
  • 举报
回复
是不是也是想更加安全
dmhorse 2003-09-12
  • 打赏
  • 举报
回复
我记得以前查过应是实现不了,但用c,c++都可以,如果想在web上显示,可以写一个activex object,在要对方同意安装,也可以实现
bnuaming 2003-09-12
  • 打赏
  • 举报
回复
海望高手能给出得到网卡的代码,谢谢
dmhorse 2003-09-12
  • 打赏
  • 举报
回复
以为是取ip,对不起
ghostxinghe 2003-09-12
  • 打赏
  • 举报
回复
这些都干吗得啊?
dmhorse 2003-09-12
  • 打赏
  • 举报
回复
package mfutil.server;

public interface ServerType
{
public boolean isMatchingType(Server server);
public Server getServer(Server[] servers);
}
dmhorse 2003-09-12
  • 打赏
  • 举报
回复
package mfutil.server;

import mfutil.ValidateUtil;
/**
* A server contain it's message.
* Such as IP,Hostname
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
public class Server
{
private final String IP;
private final String HostName;
private String reason;
public static ValidateUtil vu;

/**
*
* @param IP
* @param HostName
*/
private Server(String IP,String HostName)
{
this.IP = IP;
this.HostName = HostName;
if(!this.validate())
throw new java.lang.IllegalArgumentException("Invalid argument to create server object,reason:" +
this.reason);
}

/**
* Create a server object by specified name and ip.
* @param IP
* @param HostName
* @return
*/
public static Server Create(String IP,String HostName)
{
return new Server(IP,HostName);
}

public String getIP()
{
return this.IP;
}
public String getHostName()
{
return this.HostName;
}
public String getReason()
{
return this.reason;
}

private boolean validate()
{
vu = new mfutil.ValidateUtil();

if(vu.isBlankOrNull(IP)){
this.reason = "IP address can not be null,while create server";
return false;
}
if(vu.isBlankOrNull(HostName)){
this.reason = "HostName can not be null,while create server";
return false;
}

return true;
}
}
dmhorse 2003-09-12
  • 打赏
  • 举报
回复
package mfutil;
import java.net.*;
import java.util.*;
import mfutil.server.*;

public class NetworkUtil
{

/**
* Get the server by specified server type.
*
* @param serverType The server type indicates the server
* belongs to local netwoork or outside network
* @return the server indicates a computer links to the network
*/
public static Server getServer(ServerType serverType)
{
try
{
Enumeration e = java.net.NetworkInterface.getNetworkInterfaces();
ArrayList al = new ArrayList();
while(e.hasMoreElements())
{
NetworkInterface ni = (NetworkInterface)e.nextElement();
Enumeration e2 = ni.getInetAddresses();
while(e2.hasMoreElements())
{
InetAddress ia = (InetAddress)e2.nextElement();
Server server = Server.Create(ia.getHostAddress(),ia.getHostName());
al.add(server);
}
}
Server[] servers = new Server[al.size()];
al.toArray(servers);
return serverType.getServer(servers);
}
catch(java.net.SocketException e)
{
throw new mfutil.MFUtilException("Can not get the ip address to initalzie server object");
}
}

public static void main(String args[])
{
mfutil.server.LocalServerType lst = new LocalServerType();
Server server = NetworkUtil.getServer(lst);
System.out.println(server.getIP());
System.out.println(server.getHostName());
// LocalSeverType st = new LocalServerType();
//System.out.println(NetworkUtil.getLocalIP(args[0]));
}
}

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧