1.

Solve : Hosts file Help?

Answer»

I did not know where to postt this, but I will post it here.... I want to know if it's possible to create some sort of file(batch or whatever) that can configure the hosts file in a certain way when you open it. Like a file that blocks a certian site when you run it, and then another one which allows the site again, when you run IT...

Bump, please does anyone knnow?? Or amybe this should be moved...Bumping is a very bad idea, it is considered very bad manners, and makes helpful answers less, rather than more, likely.

The answer is "Yes, and if you show your efforts here, we will help you improve them".

Um, I didn't bump this. I bumped the otehr one that I had in the wrong place. And it didn't even work, so stop complaining. If you don't want to help me just say so. Don't make otehr excuses.The hosts file is just a text file and can be manipulated like any other.

I do not know how much you know about

1. writing batch scripts and

2. how the hosts file WORKS.

Please clarify.
Wow Mr. Google,

I recommend being a BIT more polite if you want your questions answered. Quote from: Khasiar on August 03, 2008, 02:07:26 AM

Wow Mr. Google,

I recommend being a bit more polite if you want your questions answered.

Wise words from Khasiar. This boy will GO far    i hope soAlso I should be humble and remember that we answer questions not just to help and inform the original poster but also anyone else who has a similar problem or is just curious.

So. The Hosts file in Windows is a text file. Each line contains an IP address and a host name, in that order, separated by at least one space.

Example:

Code: [Select]212.140.189.10 www.tesco.com
When a request to connect to a host name is made by a program for example a WEB browser, or any other other program, the system looks first in the Hosts file and if the host name is found, the IP address on that line is used. If it is not found, then a DNS lookup is performed.

If it is desired to block a particular site, then that host name can be given the IP address of LOCALHOST, the local computer, which is always 127.0.0.1

Code: [Select]127.0.0.1 www.blocked-site.com
Now any attempt to read www.blocked-site.com will result in an error page.

There is the possibility that malicious editing of the Hosts file could redirect traffic from a desired site to another one. This is why many security applications protect the Hosts file and monitor attempts to alter it.





Quote from: Dias de verano on August 03, 2008, 02:49:53 AM
Also I should be humble and remember that we answer questions not just to help and inform the original poster but also anyone else who has a similar problem or is just curious.

So. The Hosts file in Windows is a text file. Each line contains an IP address and a host name, in that order, separated by at least one space.

Example:

Code: [Select]212.140.189.10 www.tesco.com
When a request to connect to a host name is made by a program for example a web browser, or any other other program, the system looks first in the Hosts file and if the host name is found, the IP address on that line is used. If it is not found, then a DNS lookup is performed.

If it is desired to block a particular site, then that host name can be given the IP address of LOCALHOST, the local computer, which is always 127.0.0.1

Code: [Select]127.0.0.1 www.blocked-site.com
Now any attempt to read www.blocked-site.com will result in an error page.

There is the possibility that malicious editing of the Hosts file could redirect traffic from a desired site to another one. This is why many security applications protect the Hosts file and monitor attempts to alter it.







I thought it was 0.0.0.0 that's what I use. I know a little about batch scripts. And yes, my sucurity programs do monitor it. So, I'll give this code  a try:

Code: [Select]echo off
echo 0.0.0.0 www.facebook.com >> hosts
exit
I have a feeling this isn't quite there yet. Quote from: Mr. Google on August 03, 2008, 09:09:30 AM

I thought it was 0.0.0.0 that's what I use.

127.0.0.1 is the local machine, and using it as a block address in the Hosts file is the normal way. 0.0.0.0 is a "nil host" address and works just as well.

Quote
I know a little about batch scripts. And yes, my sucurity programs do monitor it. So, I'll give this code  a try:

Code: [Select]echo off
echo 0.0.0.0 www.facebook.com >> hosts
exit
I have a feeling this isn't quite there yet.

It adds a host to be blocked, but how to remove it?

something like this maybe

Remove a host from hosts file

syntax batchfile hostname

e.g. call it unblock.bat & use it thus: unblock www.hostname.com

Code: [Select]echo off
cd /d c:\windows\system32\drivers\etc
if exist hosts2 del hosts2
type hosts | find /v /i "%1" > hosts2
copy /y hosts2 hosts

I'm not quite sure if I understand that... Quote from: Mr. Google on August 04, 2008, 09:00:41 AM
I'm not quite sure if I understand that...

I was afraid of that.

If you do not understand that code, you should not be poking around in system folders.
Quote from: Dias de verano on August 04, 2008, 11:04:38 AM
Quote from: Mr. Google on August 04, 2008, 09:00:41 AM
I'm not quite sure if I understand that...

I was afraid of that.

If you do not understand that code, you should not be poking around in system folders.


*ignore comment*


Discussion

No Comment Found