0

I'm trying to write a little application that will block sites (ip) while using browser (chrome, ie, firefox). It can also redirect to other site. As long as user won't be able to use this site I would be satisfied with result.

The problem is that I've searched few hours for solution in google and I still can't find good solution to my problem. There were two solutions for now:

  1. Use host file - this would be a little problematic for my aplication, because I want to block site for period of time. If application will crash - it won't redo host file.
  2. Use "Windows Filtering Platform" - it's written in C++ so it will be harder for me to do. I would love to use java. I can still use C++ in java application but it still isn't satisfying solution.

I would appreciate for any help.

I think I have found solution: Blocking a website from access for all browsers

Well will try :). But still if anybody have any better ideas don't hesitate to answer this post :).

Community
  • 1
  • 1
Crushnik
  • 408
  • 5
  • 16

1 Answers1

0

I did a similar work some time ago, I used the hosts files to block all the entries that spybot search & destroy marked as "dangerous" sites. If you want to secure the site will be freeed when the app crashes, you could use a second program or thread (don't know how complex your application is) that checks if the programm is still running.

Microsoft has the following entry for displaying task names:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa446864(v=vs.85).aspx

Maybe try this code and check for your application to be alive. However, the user will notice a second task in his taskmanager........!

To patch host files I used this java-method which saves entrys from a Default list model:

try
{
  BufferedWriter out;
  this.out = new BufferedWriter(new FileWriter("C:\\Windows\\System32\\drivers\\etc\\hosts"));

  for (int save = 0; save < Blocker.model.size(); save++) {
    this.out.write((String)Blocker.model.getElementAt(save));
    this.out.newLine();
  }

  this.out.close();
} catch (IOException fail) {
  JOptionPane.showMessageDialog(null, "Speichern konnte nicht abgeschlossen werden", 
    "About", 0);
}

I'm not sure if this will really help you, anyway good luck at your project.

(Note that you have to run as administrator to get write rights to hosts-file)

Lézard
  • 11
  • 2