⼀个简单的IP地址管理系统源代码import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.StringTokenizer;
/*
* Created on 2005-1-12
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
/**
* @authorStarshus
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class IPBook
{
static boolean hasIP;
public static void main(String [] args)
throws Exception
{
int choice = -1;
while (choice != 0)
{
IPBook ipBook = new IPBook();
System.out.print("1.增加IP地址/n" +
"2.查IP地址/n" +
"3.删除IP地址/n" +
"0.退出程序/n输⼊:");
BufferedReader in =
new BufferedReader (
new InputStreamReader (System.in));
String string = in.readLine();
choice = Integer.valueOf(string).intValue();
switch(choice)
{
case 1:{
System.out.print("请以IP标准格式输⼊IP:/n" +
"⽐如127.0.0.1/n" +
"输⼊:");
BufferedReader input =
new BufferedReader (
new BufferedReader (
new InputStreamReader (System.in));
String str = adLine();
System.out.println(str);
ipBook.writeIP(str);
}break;
case 2:{
System.out.print("请输⼊你要查IP地址的头地址/n" + "⽐如你要查127.0.0.1的话就请输⼊127/n" +
"输⼊:");
BufferedReader input =
new BufferedReader (
new InputStreamReader (System.in));
String str = adLine();
long l = Integer.valueOf(str).longValue();
ipBook.findIP(l);
if(hasIP)
{
String result = ipBook.findIP(l);
System.out.println(result);
}else{
System.out.println("没有到:(");
}
}break;
case 3:{
System.out.print("请输⼊你要删除IP地址的头地址/n" + "⽐如你要删除127.0.0.1的话就请输⼊127/n" +
"输⼊:");
BufferedReader input =
new BufferedReader (
new InputStreamReader (System.in));
String str = adLine();
long l = Integer.valueOf(str).longValue();
ipBook.deleteIP(l);break;
}
}
}
}
public void inputIP(String ip)
throws Exception
{
try{
BufferedReader in1 =
new BufferedReader (
new FileReader(""));
String s1 = "",s2 = "";
while ((s1 =adLine())!= null)
{
s1 = s1+"/n";
s2 = s2 + s1;
}
s2 = s2 + ip;
DataInputStream in2 =
new DataInputStream(
new ByteArrayInputStream((s2.getBytes()))); DataOutputStream out =
DataOutputStream out =
new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream("")));
while (in2.available() != 0)
{
out.ad());
}
in2.close();
out.close();
System.out.println("写"+ip+"到⽂件中!"); }catch(Exception e){}
}
public String findIP(long ip)
throws Exception
{
hasIP=true;
String readLine ="";
String result="";
try{
BufferedReader in =
new BufferedReader (
new FileReader(""));
long top;
while ( (readLine = in.readLine())!=null)
{
top = topTokenizer(readLine);
if (top == ip)
{
result += readLine+"/n";
}
}
if(result=="")
hasIP= false;
}catch(Exception e){}
return result;
}
public long topTokenizer(String ip)
throws Exception
{
String top = "";
try{
StringTokenizer st = new StringTokenizer (ip,"."); top = st.nextToken();
}catch(Exception e){}
return Integer.valueOf(top).longValue();
}
public boolean isIP(String str)
throws Exception//判断格式是否正确
{
try{
StringTokenizer st = new StringTokenizer (str ,"."); String s1="",s2="",s3="",s4="";
s1 = st.nextToken();
s2 = st.nextToken();
s3 = st.nextToken();
s3 = st.nextToken();
s4 = st.nextToken();
}
catch(Exception e){}
return true;
}
public void writeIP(String ip)//向⽂件中加写IP地址throws Exception
{
try{
if(isIP(ip))
{
try{
inputIP(ip);
}catch(IOException e){}
}else
}catch(Exception e){}
}
电影源代码 下载
public void deleteIP(long ip)//⽤头地址删除ip throws Exception
{
String find = "";
String ss = "";
findIP(ip);
if(hasIP)
{
try{
find = findIP(ip);
String temp = "";
BufferedReader in =
new BufferedReader(
new FileReader(""));
while ( (adLine())!=null )
{
if(topTokenizer(temp)!=ip)
{
ss += temp+"/n";
}
}
BufferedReader in2 =
new BufferedReader(
new StringReader(ss));
String sss = "";
PrintWriter out =
new PrintWriter (
new BufferedWriter (
new FileWriter("")));
while ( (sss = adLine()) != null)
{
out.println(sss);
}
out.close();
System.out.println("已删除.");
}
catch(Exception e){}
catch(Exception e){}
}else{
System.out.println("没有到:("); }
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论