Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import jdk.nashorn.internal.runtime.ListAdapter;
- import java.io.*;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.regex.Pattern;
- import java.util.regex.Matcher;
- public class Main {
- public static void main(String[] args) {
- /* ZAD 1
- String dna = "ACCTTGAACTCCCCC";
- String regex = "[ACTG]+";
- Pattern pattern = Pattern.compile(regex);
- Matcher matcher = pattern.matcher(dna);
- if (matcher.matches()) {
- System.out.println(matcher.group(0));
- } else System.out.println("No maches");
- */
- /*
- String dna = "ATCAACCTAC";
- String regex = "ATC([ACTG]+)(TAA|TAC|TGA)";
- Pattern pattern = Pattern.compile(regex);
- Matcher matcher = pattern.matcher(dna);
- if (matcher.matches()) {
- System.out.println(matcher.group(1));
- } else System.out.println("No matches");
- */
- String path = "./res/serverLog.txt";
- ArrayList<String> lines = new ArrayList<>();
- ArrayList<String> ips = new ArrayList<>();
- try {
- BufferedReader reader = new BufferedReader(new FileReader(path));
- String line;
- while ((line = reader.readLine()) != null) {
- lines.add(line);
- }
- 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]?)";
- Pattern pattern = Pattern.compile(regex);
- for (String line_ : lines) {
- Matcher matcher = pattern.matcher(line_);
- while (matcher.find()) {
- ips.add(matcher.group());
- }
- }
- for (String ip : ips) {
- System.out.println(ip);
- }
- }catch (Exception ex) {
- ex.printStackTrace();
- }
- ArrayList<String[]> ipArr = new ArrayList<>();
- ArrayList<Integer> ipInt = new ArrayList<>();
- for (String ip : ips) {
- ipArr.add(ip.split("\\."));
- }
- for (String[] ipss : ipArr) {
- for (String ip : ipss) {
- ipInt.add(Integer.parseInt(ip));
- }
- }
- for (Integer test : ipInt) {
- System.out.println(test);
- }
- ArrayList<String> ipv6s = new ArrayList<>();
- for (Integer ipv6 : ipInt) {
- ipv6s.add(Integer.toHexString(ipv6));
- }
- try {
- BufferedWriter writer = new BufferedWriter(new FileWriter(new File("test.txt")));
- int i = 0;
- for (String ip : ipv6s) {
- writer.write(ip);
- writer.write('\n');
- }
- writer.close();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement