Advertisement
Guest User

lmao

a guest
Jan 21st, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.90 KB | None | 0 0
  1. package com.company;
  2.  
  3. import jdk.nashorn.internal.runtime.ListAdapter;
  4.  
  5. import java.io.*;
  6. import java.util.ArrayList;
  7. import java.util.Arrays;
  8. import java.util.List;
  9. import java.util.regex.Pattern;
  10. import java.util.regex.Matcher;
  11.  
  12. public class Main {
  13.  
  14.     public static void main(String[] args) {
  15.         /* ZAD 1
  16.         String dna = "ACCTTGAACTCCCCC";
  17.         String regex = "[ACTG]+";
  18.  
  19.         Pattern pattern = Pattern.compile(regex);
  20.         Matcher matcher = pattern.matcher(dna);
  21.  
  22.         if (matcher.matches()) {
  23.             System.out.println(matcher.group(0));
  24.         } else System.out.println("No maches");
  25.         */
  26.  
  27.         /*
  28.         String dna = "ATCAACCTAC";
  29.         String regex = "ATC([ACTG]+)(TAA|TAC|TGA)";
  30.  
  31.         Pattern pattern = Pattern.compile(regex);
  32.         Matcher matcher = pattern.matcher(dna);
  33.  
  34.         if (matcher.matches()) {
  35.             System.out.println(matcher.group(1));
  36.         } else System.out.println("No matches");
  37.         */
  38.         String path = "./res/serverLog.txt";
  39.         ArrayList<String> lines = new ArrayList<>();
  40.         ArrayList<String> ips = new ArrayList<>();
  41.  
  42.  
  43.         try {
  44.             BufferedReader reader = new BufferedReader(new FileReader(path));
  45.  
  46.             String line;
  47.             while ((line = reader.readLine()) != null) {
  48.                 lines.add(line);
  49.             }
  50.  
  51.             String regex = "(((25[0-5])|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)";
  52.  
  53.             Pattern pattern = Pattern.compile(regex);
  54.  
  55.             for (String line_ : lines) {
  56.                 Matcher matcher = pattern.matcher(line_);
  57.  
  58.                 while (matcher.find()) {
  59.                     ips.add(matcher.group());
  60.                 }
  61.             }
  62.  
  63.             for (String ip : ips) {
  64.                 System.out.println(ip);
  65.             }
  66.  
  67.         }catch (Exception ex) {
  68.             ex.printStackTrace();
  69.         }
  70.  
  71.         ArrayList<String[]> ipArr = new ArrayList<>();
  72.         ArrayList<Integer> ipInt = new ArrayList<>();
  73.         for (String ip : ips) {
  74.             ipArr.add(ip.split("\\."));
  75.         }
  76.  
  77.         for (String[] ipss : ipArr) {
  78.             for (String ip : ipss) {
  79.                 ipInt.add(Integer.parseInt(ip));
  80.             }
  81.         }
  82.  
  83.         for (Integer test : ipInt) {
  84.             System.out.println(test);
  85.         }
  86.  
  87.         ArrayList<String> ipv6s = new ArrayList<>();
  88.  
  89.         for (Integer ipv6 : ipInt) {
  90.             ipv6s.add(Integer.toHexString(ipv6));
  91.         }
  92.  
  93.         try {
  94.             BufferedWriter writer = new BufferedWriter(new FileWriter(new File("test.txt")));
  95.             int i = 0;
  96.  
  97.             for (String ip : ipv6s) {
  98.                 writer.write(ip);
  99.                 writer.write('\n');
  100.  
  101.             }
  102.  
  103.             writer.close();
  104.         } catch (Exception ex) {
  105.             ex.printStackTrace();
  106.         }
  107.  
  108.  
  109.  
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement