hey guys,
i was wondering is there a way in java to block all incoming/outgoing tcp/ip connection to a computer (i want to build a basic firewall system which as for now just block all connections or allow them at a click of a button)
thanks!
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
hey guys,
i was wondering is there a way in java to block all incoming/outgoing tcp/ip connection to a computer (i want to build a basic firewall system which as for now just block all connections or allow them at a click of a button)
thanks!
Hello BraveProgrammer and welcome to the Java Programming Forums.
Do you know which ports you wish to block or do you want to block every port?
Read up on Java Networking - Networking Basics (The Java™ Tutorials > Custom Networking > Overview of Networking)
I think you will need to write something that listens on a certain port and then denies connection.
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
hey, thanks, glad to be here
actually for this moment i would like to be able to block the entire connection so ill rather block all the ports instead of listening to each and every port..
ill defenatly read on Java Networking but i persume it will explain about creating and blocking connections specified by certain ports, do u know a way to generalize it and block it all?
Hmm.. I'm not too sure how you would go about blocking every port. When I have done something similar in the past, the application was listening on a certain port and rejected the connection that way.
If a port isn't open, no one will be able to connect to it anyway.
Hopefully someone else can shed some light on this...
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
I believe most operating systems prevent opening multiple connections using the same port (linux does, and I believe Windows and MacOS do too). You could try opening connections to every port to prevent any other connections to that port, but you will run into a few problems:
1. You have no way of knowing when another application wants to use that port. This is fine if you want to just block that port, but you can't release the port without either random guessing or making every application use some API through your program to request access to that port (this just won't happen)
2. This assumes your application has unhindered access to every single port 0-0xffff. This will never be the case. Address 0-1024 are almost always reserved by the OS, and either will disallow opening them or will require super-user/administrator rights. This also means that your application must connect to the port before any other application connects to it.
3. I don't think there is a way for you to forcibly terminate a connection if it already exists (at least not in pure Java)
If you want to stop all port communication, simply disable your network card.