import java.io.*;
import java.util.*;

public class IPGetter
{
  public static void main(String[] args) throws FileNotFoundException
  {
    FileReader reader = new FileReader(args[0]);
    Scanner in = new Scanner(reader);
    PrintWriter out;
    if(args.length>1)//if user does not specify an output filename
    {
      out = new PrintWriter(args[1]); //can allow user to choose output name
    }
    else
    {
      out = new PrintWriter("outputIPs.txt");
    }

    //PrintWriter  out = new PrintWriter("outputIPs.txt");
    int numIPs = 0;
    while(in.hasNext())
    {
      String temp = in.next();
      //System.out.println(temp);
      if(temp.matches("\\d.+\\d.+\\d.+\\d+")) //if the string matches the pattern "number.number.number.number"
      {
        numIPs++;
        if(numIPs > 1)//keeps first IP address that represents final location from printing to file
        {
         out.println(temp);
        }
      }
      if(temp.matches("\\[\\d.+\\d.+\\d.+\\d\\]+"))//if the string matches the pattern "[number.number.number.number]"
      {
        numIPs++;
        if(numIPs > 1)
        {
         out.println(temp.substring(1,temp.length()-1));
        }
      }
    }       
    
    in.close();
    out.close();
  }
  
  
}

