I don't think you can, you won't get even close I think. The problem is that a firewall/connection monitor requires intervention at a very low level in the network coding. Java by default, is a very high level language and runs inside a JVM, a shielded environment. You might get around some limitations by using native code, but I don't believe a pure java firewall can be done, it will not be efficient, nor will it have full network support.
Actually there are many firwall builders for Linux that are written in Java. However these builders are only GUI nad they create only firwall rules. After rules are created then firewall manipulation programm (like ipfwadm, ipchains..) is called. This is the most common way.
You may also create native llibrary that directly calls tcp stack packet-filter methods.
The third way is if you have a java os and tcp/ip stack is written in java (i've seen ppp java stack) you can call java api to manipulate filters.
Hi usama_ra,
Please go through it, so that you will get a brief idea about the firewall.
Applets are subject to heavy security constraints when executing under the control of a browser. Applets are unable to access the local file-system, to bind to local ports, or to connect to a computer via
sockets other than the computer from which the applet is loaded. While it may seem to be an annoyance for developers, there are many good reasons why such tight constraints are placed on applets.
Applets could bind to well known ports, and service network clients without authorization or consent. Applets executing within firewalls could obtain privileged information, and then send it across the
network. Applets could even be infected by viruses, such as the Java StrangeBrew strain. Applets might become infected without an applet author's knowledge and then send information back that
might leave hosts vulnerable to attack.
Signed applets may be allowed greater freedom by browsers than unsigned applets, which could be an option. In cases where an applet must be capable of network communication, HTTP can be used
as a communication mechanism. An applet could communicate via java.net.URLConnection with a CGI script, or a Java servlet. This has an added advantage - applets that use the URLConnection will be
able to communicate through a firewall.
Also please refer this URL which has a good information.
http://www.securingjava.com/chapter-five/chapter-five-5.html
I hope this will help you.
Thanks
Bakrudeen
Technical Support Engineer
Sun MicroSystems Inc, India
Well, the only possibility i see would be to listen on all ports, which would be a terrible ressource usage, but that how a pure Java FW could work BUT would be still dependant on the underlying TCP/IP Stack giving you no full security (as e.g. the tcp/ip stack of Win has enough bugs usefull for an attacker to crack inside).
However, I have seen Java implementations of proxies, so a native Low-Level Firewall and a Java proxy for specific services (e.g. HTTP, where your proxy can log the URL's or log Headers ...) would be possible and more realistic that a pure Java Firewall.
Hi Bakrudeen ,shadowcat45 :
thank u for your replaying , u help me so much .
and i just want to tell u what i need to do and how i think i will do it .
* first i have won a free shcroll ship to study java and i will Enter SCJP in 2 weeks After that i hope to make a my graduate project "a Firewall in pure java . "
* i thing i will make my firewall operate on Application Layer not on Network Layer .
* what i need to know what is the ways i can use to read ip Packets and to communicate with TCP/IP Stack .
thanks
* and about listening to all ports there is class "SoketPremesion" whice can used to listen to all ports !!! i don't know if this is a wite choise or not ..
thanks