Hosts: Linebreaks (CR+LF) for Windows-Users

Created on 29 Jul 2017  路  32Comments  路  Source: StevenBlack/hosts

Would be nice if the lists gets linebreaks (CR+LF) for Windows-Users.
Think, Windows-Users should be able to read the files with 'Editor', too.

Windows enhancement

Most helpful comment

Hi @StevenBlack and everyone.
I may have a solution for this issue for you.
I have created a PowerShell module that includes an Install-GCHostsFileBlockList function.

The repository is located here: https://github.com/grantcarthew/GCPowerShell
The module on that page is here: https://github.com/grantcarthew/GCPowerShell#gchostsfile
The module file is here: https://github.com/grantcarthew/GCPowerShell/blob/master/GCHostsFile/Install-GCHostsFileBlockList.ps1

I have published the GCHostsFile module to the PowerShell Gallery. This makes the install very easy.

To install the GCHostsFile module follow these steps on a system with an updated version of PowerShell:

  • Open PowerShell as administrator.
  • Install-PackageProvider -Name NuGet -Force (This adds support for the PS Gallery)
  • Install-Module -Name GCHosts -Force (This installs the module)

Once the above is done the Install-GCHostsFileBlockList function will work.

The function downloads your brilliant hosts file to a temp file then replaces the Windows hosts file fixing all CR-LF issues.

The Install-GCHostsFileBlockList function has a parameter -Extension which takes the following arguments:

'FakeNews',
'Gambling',
'Porn',
'Social',
'FakeNews+Gambling',
'FakeNews+Porn',
'FakeNews+Social',
'Gambling+Porn',
'Gambling+Social',
'Porn+Social',
'FakeNews+Gambling+Porn',
'FakeNews+Gambling+Social',
'FakeNews+Porn+Social',
'Gambling+Porn+Social',
'FakeNews+Gambling+Porn+Social'

If Windows users want to use your hosts file they only need to follow these steps.

I'll add a PR for your README if you like.

All 32 comments

How do the NIX systems treat CRLF in the file ?

I don't know!
But you can test it e.g. with this file: https://github.com/Tobias-B-Besemer/hosts

dos2unix && unix2dos conversion ?

No conversion! I guess that the CRLF-Linebreak change nothing for NIX-Users...
...and it makes the file readable for Windows-Users...

Either way is readable by your computer, just not so easily by a human. But you can easily add line breaks by reading it through more or running it through a for loop and then redirecting to a file. If you're not a scripter, you could also just use my AutoUpdate script and it does all that automatically.

By the way, I just reread the first post here. If it's about reading it in an editor, Wordpad reads NIX files just fine, so this issue is closed. Windows+R and type in either write or wordpad. If you want to keep it that way for notepad or other text editors that get confused, just literally open wordpad and save without doing anything else and it will save it with line breaks and you can open it again with the other text editor.

AFAIK Wordpad will not change the linebreaks by saving.
Why not make the hostsfile with CR+LF that it is readable for everyone in every editor?

^

AFAIK Wordpad will not change the linebreaks by saving.

Whether sadly, that's not the case: I converted my BAT file, originally written using Notepad++ in CR+LF, into the Unix LF, opened in WordPad, added a letter, saved, closed, opened in Notepad++ and the letter was right where I placed it, and it reads Windows (CR LF) in the corner when it should be Unix (LF).

I'm on Window$ 7 Ultimate SP1 x64.

Yeah, it's been doing that for ages. Like I said, the other easy alternative is just Windows+R, type cmd, and then type this:
more filenameLF.py > filenameCRLF.py
It will also format it for Windows.

We'll see what Steven decides. If the PR doesn't go through, I'll just make a script for you to automatically pull all the hosts in CRLF. I already do that anyway for the DualServer repo, so can just make some quick edits for you and I'll drop it in the AutoUpdate repo but won't include it in the zip.

I just opened the latest hosts file using three different editors on Windows. I can see no problem here.

So the problem clearly isn't on Windows affecting all windows users. It's particular editors that exhibit this issue.

@Tobias-B-Besemer maybe try using a better editor? I don't consider Notepad.exe, for example, to be a serious editor.

Closing.

It was just because Notepad.exe (editor.exe) is the default editor in Windows...

I don't care about Microsoft abandonware.

I'm sorry @Tobias-B-Besemer; what I said above ^^^ was too harsh.

Reopening this issue, in light of Pull Request #377.

I made him a normalizer anyway, but just made a repo for it rather than combining it with another one as it could be useful by itself.

https://github.com/ScriptTiger/CRLF-Normalizer

Sorry for being OT:
We did an auto-updater, too.
https://github.com/LV-Crew/HostsManager/releases

@Tobias-B-Besemer, I like your contact information on the website. Maybe you would be interested in Ricochet IM? You might not have a problem with putting a real account name down for that and everybody on your team could have one, since I know you are all massive Tor supporters.

https://ricochet.im/

@ScriptTiger, thanks for the hint! I made some 'ads' for the project...

@Tobias-B-Besemer, can this issue be closed at this point? There's both the Normalizer and the Hosts Packages legacy support repo to address this outside of this particular repo itself.

Thanks for asking! If @StevenBlack don't want it, you can close it...

What is the 'Hosts Packages legacy support repo'?

It's similar to the "non-GitHub mirror" here in that it uses the GitHub Pages web service so it doesn't run into the same errors you get when trying to download the files directly from the git repo pages with some clients, except it hosts both ZIP and raw hosts files with CRLF line endings. It's a compatibility repo for people that need either CRLF and/or ZIP files. After more testing and user feedback, it seems as though the ZIP files were just a misunderstanding of some kind in the first place and never actually needed. I was going to terminate it, but it was getting some traffic. I am not sure which aspect of it people appreciate though, so more feedback on what about it is helpful would be appreciated.

https://scripttiger.github.io/hosts-packages/

We fixed the CRLF-Problem in our app and the asking for use a 'CRLF-Standard' was more in general...
I would be happy if you give our app a try and maybe fill a/some issues for it...
https://github.com/LV-Crew/HostsManager/releases

I have downloaded your stuff already, but I haven't had time to go through the source yet and build it. Since your application is security related, you should consider its complexity when designing it. The more transparent and easy to follow something is, the more trusting people can be about it. I am not saying I don't trust you, but I have to follow certain rules for security related applications. Being a fellow Tor supporter, I am sure you understand. I have read your documentation though and the feature set seems pretty awesome. As soon as I have read through all the source and have it up and running in a sandbox, I'll definitely unload all my issues on you.

Hi @StevenBlack and everyone.
I may have a solution for this issue for you.
I have created a PowerShell module that includes an Install-GCHostsFileBlockList function.

The repository is located here: https://github.com/grantcarthew/GCPowerShell
The module on that page is here: https://github.com/grantcarthew/GCPowerShell#gchostsfile
The module file is here: https://github.com/grantcarthew/GCPowerShell/blob/master/GCHostsFile/Install-GCHostsFileBlockList.ps1

I have published the GCHostsFile module to the PowerShell Gallery. This makes the install very easy.

To install the GCHostsFile module follow these steps on a system with an updated version of PowerShell:

  • Open PowerShell as administrator.
  • Install-PackageProvider -Name NuGet -Force (This adds support for the PS Gallery)
  • Install-Module -Name GCHosts -Force (This installs the module)

Once the above is done the Install-GCHostsFileBlockList function will work.

The function downloads your brilliant hosts file to a temp file then replaces the Windows hosts file fixing all CR-LF issues.

The Install-GCHostsFileBlockList function has a parameter -Extension which takes the following arguments:

'FakeNews',
'Gambling',
'Porn',
'Social',
'FakeNews+Gambling',
'FakeNews+Porn',
'FakeNews+Social',
'Gambling+Porn',
'Gambling+Social',
'Porn+Social',
'FakeNews+Gambling+Porn',
'FakeNews+Gambling+Social',
'FakeNews+Porn+Social',
'Gambling+Porn+Social',
'FakeNews+Gambling+Porn+Social'

If Windows users want to use your hosts file they only need to follow these steps.

I'll add a PR for your README if you like.

I am sure we can all appreciate your willingness to help, but drawing Steven's attention once again to this repo is a sure-fire way to get the issue closed and locked as it's leaning towards "going on and on" again. @Tobias-B-Besemer, make a new issue to raise awareness for your application, but just leave it at a single comment and don't get too spammy about it. After Steven has you on his watch list and sees you're making progress and getting traction, I am sure he wouldn't mind a readme PR for the "Third-Party Hosts Managers" section.

Bump

Thanks for asking! If @StevenBlack don't want it, you can close it...

Thank you, everyone, for input on this matter.

@StevenBlack, he gave you the honors to close it :P

I don't want to close it; it's an outstanding issue.

Right now I'm inclined to fix it in code.

Oh wow, in that case this issue took an unexpected turn. @Tobias-B-Besemer, stay posted.

Would fixing it in code or passively through git or possibly a combination provide the best balance between efficiency and compatibility?

Choose a good text editor. Notepad3 lets you set line endings.

^

Choose a good text editor. Notepad3 lets you set line endings.

Notepad3 is nothing against Notepad++.

Was this page helpful?
0 / 5 - 0 ratings