如何让服务端注册或者限制服务端的使用

笑天狂客 2004-04-10 12:09:27
请问高手们:
如何保护我所开发的jsp和servlet只在一台服务器上安装,如果在另外的服务器上安装就需要输入注册码或者不允许安装?

前提:用户不会去反编译class文件
...全文
28 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
tanndy 2004-04-29
  • 打赏
  • 举报
回复
绑定IP/网卡地址,先获取MAC地址



import java.net.InetAddress;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.text.ParseException;
import java.util.StringTokenizer;

import java.io.InputStreamReader;
import java.io.LineNumberReader;

public class NetworkInfo
{
//get IP Address (only for winzk series OS)
public static String getMacAddress() throws IOException
{
String os = System.getProperty("os.name");
try
{
if (os.startsWith("Windows"))
{
return windowsParseMacAddress(windowsRunIpConfigCommand());
}
else
{
throw new IOException("unknown operating system: " + os);
}
}
catch (ParseException ex)
{
ex.printStackTrace();
throw new IOException(ex.getMessage());
}
}

public static void main(String[] args)
{
try
{
//System.out.println("UUID = " + NetworkInfo.getMacAddress());
System.out.println(getMacAddress("202.104.32.198"));
}
catch( Exception e )
{
System.out.println(e);
}
}

private final static String windowsParseMacAddress(String ipConfigResponse) throws ParseException
{
String localHost = null;
try
{
localHost = InetAddress.getLocalHost().getHostAddress();
//System.out.println(localHost);
}
catch (java.net.UnknownHostException ex)
{
ex.printStackTrace();
throw new ParseException(ex.getMessage(), 0);
}

/* StringTokenizer
* public StringTokenizer(String str,String delim, boolean returnTokens);
* public StringTokenizer(String str, String delim);
* public StringTokenizer(String str);
*/

StringTokenizer tokenizer = new StringTokenizer(ipConfigResponse, "\n");
String lastMacAddress = null;

//判断字符串中是否还有token
while (tokenizer.hasMoreTokens())
{
String line = tokenizer.nextToken().trim();

// see if line contains IP address
if (line.endsWith(localHost) && lastMacAddress != null)
{
System.out.println( "MAC_Address = " + lastMacAddress );
System.out.println( "IPA_ddress = " + localHost );
return lastMacAddress;
}

// see if line contains MAC address
int macAddressPosition = line.indexOf(":");
if (macAddressPosition <= 0)
continue;
String macAddressCandidate = line.substring(macAddressPosition + 1).trim();
//System.out.println(macAddressCandidate);

if (windowsIsMacAddress(macAddressCandidate))
{
lastMacAddress = macAddressCandidate;
continue;
}
}
ParseException ex = new ParseException("cannot read MAC address from [" + ipConfigResponse + "]", 0);
ex.printStackTrace();
throw ex;
}

private final static boolean windowsIsMacAddress(String macAddressCandidate)
{
// TODO: use a smart regular expression
if (macAddressCandidate.length() != 17)
return false;
return true;
}

private final static String windowsRunIpConfigCommand() throws IOException
{
//run the command "ipconfig /all" in order to get the MAC INFO;
Process p = Runtime.getRuntime().exec("ipconfig /all");
InputStream stdoutStream = new BufferedInputStream(p.getInputStream());
StringBuffer buffer= new StringBuffer();
for (;;)
{
int c = stdoutStream.read();
if (c == -1)
break;
buffer.append((char)c);
}
String outputText = new String((buffer.toString().getBytes("ISO8859_1")), "GB2312");
stdoutStream.close();
System.out.println("outputText = " + outputText );
return outputText;
}

private final static String getMacAddress(String remotePcIP)
{
String str="";
String macAddress="";
try
{
Process pp= Runtime.getRuntime().exec ("nbtstat -A " + remotePcIP);
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader (ir);
for (int i = 1; i <100; i++)
{
str=input.readLine();
if (str!=null)
{
if(str.indexOf("MAC Address")>1)
{
macAddress=str.substring(str.indexOf("MAC Address")+14,str.length());
break;
}
}
}
}

catch (IOException ex)
{
}
return macAddress;
}


}


然后在servlet里面绑定!不用多说了哦:)
笑天狂客 2004-04-27
  • 打赏
  • 举报
回复
高手看过来。。。。
笑天狂客 2004-04-21
  • 打赏
  • 举报
回复
没人知道么?
笑天狂客 2004-04-18
  • 打赏
  • 举报
回复
那个服务器是不能上网的,只在内部局域网。只要给符合要求的ip地址不就可以绕过注册了么?
jkit 2004-04-10
  • 打赏
  • 举报
回复
首先不明白你为什么有这个要求。
如果要达到这个目的,还是有办法的,比如在你的class里面判服务器的ip,如果不是授权ip就报错或者就启动认证程序要求输入注册码才将此ip授权。
不过我总觉得这种要求就不是很合理的要求!而且还有用户不会去反编译class文件的前提!
笑天狂客 2004-04-10
  • 打赏
  • 举报
回复
打个rar包的话,你最终还是要解开啊,用户只需将应用文件(jsp,class文件)拷贝到另外一台机子上就行了呀。
pleonheart 2004-04-10
  • 打赏
  • 举报
回复
打个rar,呵呵,其他不说了
jk3278jk 2004-04-10
  • 打赏
  • 举报
回复
用数据库存储用户名和注册码
CoolAbu 2004-04-10
  • 打赏
  • 举报
回复
不再灌水 说的方法可以达到你的要求,你在Servlet里面做一个判断,判断服务器的IP,如果IP不符合要求的就不允许运行。
tanndy 2004-04-10
  • 打赏
  • 举报
回复
绑定IP/网卡地址啊

81,092

社区成员

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

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