Jump to content

Blocking www.Facebook.com via Hosts file


 Share

Recommended Posts

@ The Kandie Man

That script looks like there is still only 1 space between the 127.0.0.1 and the address

I'm quite sure that the minumum is 2 and I know for sure that the MVPS hosts file uses 3 tabs to be sure of enough white space. I don't recall what the whitespace was for but I do now that it won't work if there is not enough.

Edit: I just checked and Microsoft claims it will work with 1 space for XP but even their examples use a minumum of 5 spaces.

I was going to use two after you suggested, but after i saw this the top of the hosts file I just used one space.

# Copyright © 1993-1999 Microsoft Corp.

#

# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.

#

# This file contains the mappings of IP addresses to host names. Each

# entry should be kept on an individual line. The IP address should

# be placed in the first column followed by the corresponding host name.

# The IP address and the host name should be separated by at least one

# space.

#

# Additionally, comments (such as these) may be inserted on individual

# lines or following the machine name denoted by a '#' symbol.

Thanks for letting me know anyway. I hate putting up stuff that is wrong.

- The Kandie Man ;-)

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

@ The Kandie Man

That's what it says alright. But look down that file and see how many spaces MS actually used. I wish I could remember what the reason for 2 or more was. Old age is slowing the process.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

It was dumb of Microsloth to use those files without extensions. Just my opinion.

The people who created the OS were influenced by (and probably borrowed some code) by the fact that they had made a *nix (VMX?) system. If I recall right that was the reason they were hired to do the job..<_< You also have the POSIX specification. To get defense contracts some level of that spec were to be met.

And most people at the time disagrees with you. They thought it was really stupid not to implement a #! scheme to indicate the type of file rather than using an extension.

Link to comment
Share on other sites

This should do exactly what you want:

#include <array.au3>
#include <file.au3>

Dim $s_FileInputPath = "hosts"
Dim $s_FileOutputPath = "hosts2";for you this will be the same as the input
Dim $i_InserLineNumber = 25
Dim $s_InserLineContent = "127.0.0.1 www.facebook.com"
;A return value 1 indicates success.  A return value of 0 or less indicates failure.
WriteLineToFile($s_FileInputPath ,$s_FileOutputPath ,$i_InserLineNumber,$s_InserLineContent)

Func WriteLineToFile($s_FileName,$s_FileOutputName,$i_LineNumber,$s_Line)
Local $as_HostsContent
If Not _FileReadToArray($s_FileName,$as_HostsContent) Then Return 0
;~ _ArrayDisplay($as_HostsContent)

;This if statement extends the number of lines in the file if the line that is being inserted to is currently larger than the total number of lines in the file
If UBound($as_HostsContent) < $i_LineNumber  Then
    ReDim $as_HostsContent[$i_LineNumber+1]
EndIf

If Not _ArrayInsert($as_HostsContent,$i_LineNumber,$s_Line) Then Return -1
;~ _ArrayDisplay($as_HostsContent)

If Not _FileWriteFromArray($s_FileOutputName,$as_HostsContent,1) Then Return -2
Return 1
EndFunc

Hope you find it useful.

- The Kandie Man ;-)

Hey Kandie Man,

I just had to edit the below lines to get it to work.

Dim $s_FileInputPath = @SystemDir & "\drivers\etc\hosts"

Dim $s_FileOutputPath = @SystemDir & "\drivers\etc\hosts"

Thanks for the input.

Link to comment
Share on other sites

I thought the response I entered 4 days ago was adequate, especially considering this is only a temporary fix.

Yea your response you entered awhile ago is working fine, and precisely what I had asked for, a quick temporary fix.

What The Kandie Man came up with works as well, I like to see the various solutions, it helps me get a better idea on how AutoIt works and what can be done with it.

Both are appreciated.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...