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 * /
/ ** * @author Starshus * 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 "= -1; while (choke! = 0) {ibbook ipbook = new ipbook (); system.out.print (" 1. Increase IP Address / N " " 2. Find IP Address / N " " 3. Delete IP address / n " " 0. Exit program / N input: "); bufferedreader in = new bufferedreader (new inputr (system.in)); string string = in.readline (); choice = Integer.Valueof (String) .intValue (); switch (choice) {case 1: {system.out.print ("Please enter IP: / n" "in IP standard format, such as 127.0.0.1/n" " Enter: "); BufferedReader Input = New BufferedReader (ne) W InputStreamReader (System.IN)); string str = input.readline (); system.out.println (STR); ipbook.writeip (str);} Break; case 2: {system.out.print ("Please enter You have to find the header address of the IP address / N " ", if you want to find 127.0.0.1, enter 127 / N " " input: "); bufferedReader Input = New BufferedReader (NEW InputStreamReader (System.in)); String str = INPUT.READLINE (); long l = integer.valueof (str) .longvalue ();
IPBook.Findip (L); if (Hasip) {string result = ipbook.findip (l); System.out.Println (Result);} else {system.out.println ("Nothing: (");}} Break; case 3: {system.out.print ("Please enter the header address of the IP address / N" ", please enter 127 / N" "input:"), please enter 127 / N ". BufferedReader input = new BufferedReader (new InputStreamReader (System.in)); String str = input.readLine (); long l = Integer.valueOf (str) .longValue (); ipBook.deleteIP (l); break;}}} } Public void infutip (String IP) throws exception {type = new bufferedreader ("iPbook.txt"); string s1 = "", s2 = ""; while ((S1 = in1.readli) NE ())! = null) {S1 = S1 "/ N"; S2 = S2 S1;} S2 = S2 IP; DataInputStream In2 = New DataInputStream (New ByTearrayInputStream ((S2.GetBytes ()))); DataOutputStream OUT = New DataOutputStream (New FileoutputStream (New FileoutputStream ("iPbook.txt"))); while (in2.available ()! = 0) {out.write (in2.READ ());} in2.close ();
Out.close (); system.out.println ("Write" IP "to file ipbook.txt!");} catch (exception e) {}} public string findip (long ip) throws exception {Hasip = true String readline = ""; string result = ""; try {bufferedreader in = new bufferedreader ("iPbook.txt"); long top; while ((readline = in.readline ())! = Null) {TOP = TOPTOKENIZER (READLINE); if (TOP == IP) {result = readline "/ n";}}} (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 // Decision format correct {Try {StringTokenizer ST = New StringTokenizer (Str, "."); String S1 = "", S2 = ", S3 =" " , S4 = ""; s1 = st.nextToken (); s2 = st.nextToken (); s3 = st.nextToken (); s4 = st.nextToken ();} Catch (Exception E) {} Return True;