Comments (8)
Closing this now. This is an old issue, and Windows is too fragmented. Folks are of course free to automate their own workflows.
from hosts.
Here you go.
$hostsRequest = (Invoke-Webrequest -Uri "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts")
$currentDate = ((get-date).ToUniversalTime()).ToString("dd-MM-yyyy hh-mm-ss")
$filePath = "C:\Windows\System32\drivers\etc\host-{0}.{1}"
if($hostsRequest.StatusCode -eq 200){
$captureDomainRegex = "^(?:\d{1}\.\d{1}\.\d{1}.\d{1} )(.+)"
$hosts = [PsCustomObject]@{unique=@(); duplicate=@();}
$hostsRequest.Content | out-file -filepath ($filePath -f $currentDate, "txt")
foreach ($line in Get-Content ($filePath -f $currentDate, "txt")){
if($line -match $captureDomainRegex) {
if($hosts.unique -contains $matches[1]){
$hosts.duplicate += $matches[1]
}else{
$hosts.unique += $matches[1]
}
}
}
ConvertTo-Json $hosts | out-file -filepath ($filePath -f $currentDate, "json")
}
#load json and get the count of unique entries
#(Get-Content ($filePath -f $currentDate, "json") | ConvertFrom-Json).unique.Count
This would create host.txt wherever your path is set to, then it will read that file and create
host.json with the following structure
{
"unique": [
"0koryu0.easter.ne.jp",
"1-atraffickim.tf",
"10-trafficimj.tf",
"109-204-26-16.netconnexion.managedbroadband.co.uk",
"11-atraasikim.tf",
"11.lamarianella.info",
"12-tgaffickvcmb.tf",
"13-ctscfficim.tf",
"alsoknowsit.com"
],
"duplicate": [
"11-atraasikim.tf",
"11.lamarianella.info"
]
}
from hosts.
Feel free to submit one!
The permanent location is
https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
from hosts.
Something like this one? ;-)
https://github.com/gaenserich/hostsblock
from hosts.
This one seems to work for me. You can run it with task scheduler for periodically updates.
# Create temp folder..
New-Item -ItemType Directory -Force -Path 'C:\Hosts\'
Set-Location C:\Hosts\
wget 'https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts' -OutFile hosts
# Clean up and remove dublicates ..
Get-Content hosts | Where { $_ -notmatch "\#" } | Where {$_.trim() -ne " " } | Sort-Object -Unique | Set-Content final
# Back-up and Update hostsfile..
Copy-Item -Recurse "C:\Windows\System32\drivers\etc\hosts" -Destination "C:\Windows\System32\drivers\etc\hosts.bak"
Copy-Item -Recurse ".\final" -Destination "C:\Windows\System32\drivers\etc\hosts"
# FlushDNS..
CMD.EXE /C "ipconfig /flushdns"
Write-Host "`nHosts File Updated" -ForegroundColor Green
rm .\final -Recurse
from hosts.
$hosts = "$env:windir\System32\drivers\etc\hosts"
$hosts_custom = "C:\Users\XXXXXX\OneDrive\hosts.custom.txt"
Invoke-WebRequest -Uri https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts -OutFile $hosts
if (Test-Path -Path $hosts_custom) {Get-Content $hosts_custom | Add-Content -Path $hosts}
C:\WINDOWS\system32\cmd.exe /C C:\WINDOWS\system32\ipconfig /flushdns
from hosts.
Does it count if it's not PowerShell?
https://github.com/ScriptTiger/Unified-Hosts-AutoUpdate
from hosts.
@Sn0wflake Invoke-WebRequest works only from a specific version of powershell and I have seen that on Windows Server 2008 it doesn't by default.
from hosts.
Related Issues (20)
- Addition to porn list
- add to porn blocklist
- block argo.svcmot.com HOT 5
- add to porn list HOT 2
- click.discord.com on fakenews-gambling-porn HOT 4
- block airtel analytics. HOT 6
- StevenBlack blocks GOG Store in Heroic Games Launcher HOT 2
- Mistake on line 22 HOT 2
- Sex vid HOT 1
- https://www.pornobereich.com/
- DNS Client overloaded when using biggest host file, causing "permanent" internet connection loss HOT 5
- allow statcounter it is just a website which track os and other stuff HOT 1
- Add Snapchat to the social list HOT 10
- Amplitude.com completely blacklisted by Adaway HOT 2
- Please add spiegel.com because it's NOT the english version of german newspaper spiegel.de HOT 2
- allow stat counter HOT 1
- adbox.lv and b.adbox.lv HOT 4
- Unblock fast.appcues.com HOT 2
- ## Inefficient regular expression HOT 3
- Authentic domain being blocked HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hosts.