Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×
User Journal

Journal fishdan's Journal: FirewallUpdater.java

import java.io.*;
import java.net.*;
import java.util.*;

public class FirewallUpdater {
  static Hashtable banned=new Hashtable();
  static PrintWriter pw;
  public static void main(String[] args) {
    System.out.println("Starting");
    try{
      FileWriter fw = new FileWriter("fu.log",true);
      pw = new PrintWriter(fw);
      ServerSocket sSock=null;
      System.out.println("Trying to listen on port 7328");
      sSock=new ServerSocket(7328);
      System.out.println("Listening on port 7328");
      for(;;){
        Socket sock=sSock.accept();
        System.out.println("Accepted a new connection");
        processConnection(sock);
      }

    }
    catch(Exception e){
      e.printStackTrace();
    }
  }
  public static void processConnection(Socket sock){
    try{
      if(sock.getInetAddress().getHostAddress().startsWith("192.168")){
        DataInputStream in = new DataInputStream(sock.getInputStream());
        String line;
        while((line=in.readLine())!=null){
          if(banned.containsKey(line)){
          }
          else{
            Process p=Runtime.getRuntime().exec("/sbin/iptables -A INPUT -s "+line+" -j DROP");
            banned.put(line,line);
            pw.println(new Date()+" banning "+line);
          }
        }
      }
    }
    catch(Exception e){
      e.printStackTrace();
    }
  }
}

An engineer is someone who does list processing in FORTRAN.

Working...