-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildHostsFile.ps1
188 lines (158 loc) · 7.62 KB
/
BuildHostsFile.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# Build my hosts file. Pulls from:
# 1. My own custom entries [in this repo]
# 2. Spybot S+D Immunization Entries [in this repo]
# 3. StevenBlack Hosts [pull from his GitHub]
# 4. Exceptions [defined in this file below]
# 5. YouTube ad list [pull from their GitHub]
if($IsLinux -eq $true){
$HostsFile = "$($HOME)/Desktop/hosts.txt"
$CustomEntriesFile = "$($PSSCRIPTROOT)/CustomEntriesSK.txt"
$SpybotEntriesFile = "$($PSSCRIPTROOT)/SpybotEntries.txt"
}elseif($IsMacOS -eq $true ){
$HostsFile = "$($HOME)/Desktop/hosts.txt"
$CustomEntriesFile = "$($PSSCRIPTROOT)/CustomEntriesSK.txt"
$SpybotEntriesFile = "$($PSSCRIPTROOT)/SpybotEntries.txt"
}else{
$HostsFile = "c:\users\$($env:USERNAME)\Desktop\hosts.txt"
$CustomEntriesFile = "$($PSSCRIPTROOT)\CustomEntriesSK.txt"
$SpybotEntriesFile = "$($PSSCRIPTROOT)\SpybotEntries.txt"
}
#region Put the hosts file together:
$HostsFileContent = @()
$HostsFileContent += Get-Content $CustomEntriesFile
$HostsFileContent += Get-Content $SpybotEntriesFile
$HostsFileContent += "#region########################################################################################################################################"
$HostsFileContent += "# Start of StevenBlack Hosts"
$HostsFileContent += "# A select few entries have been unblocked to ensure sites like Hulu work."
$StevenBlackHosts = (invoke-webrequest "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts")
$YouTubeAds = (Invoke-WebRequest "https://raw.githubusercontent.com/kboghdady/youTube_ads_4_pi-hole/master/youtubelist.txt")
$SmartTV1 = (Invoke-WebRequest "https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/SmartTV.txt")
$SmartTV2 = (Invoke-WebRequest "https://raw.githubusercontent.com/tarvcode/pihole-smart-tv/main/pihole-smart-tv.txt")
#$NoDupe = $StevenBlackHosts.rawcontent
#$Dedupe = $StevenBlackHosts.rawcontent | Sort-Object | get-unique
#Compare-Object -ReferenceObject $NoDupe -DifferenceObject $Dedupe
#region Define exceptions:
$Exceptions = @()
$row = new-object PSObject -Property @{
'Entry' = "0.0.0.0 cws.conviva.com";
'Comment' = "#Unblocked SK 2020/03/15 [BeachBody]";
}
$Exceptions += $row
$row = new-object PSObject -Property @{
'Entry' = "0.0.0.0 www.cws.conviva.com";
'Comment' = "#Unblocked SK 2020/03/15 [BeachBody]";
}
$Exceptions += $row
$row = new-object PSObject -Property @{
'Entry' = "0.0.0.0 zee.cws.conviva.com";
'Comment' = "#Unblocked SK 2020/03/15 [BeachBody]";
}
$Exceptions += $row
$row = new-object PSObject -Property @{
'Entry' = "0.0.0.0 www.zee.cws.conviva.com";
'Comment' = "#Unblocked SK 2020/03/15 [BeachBody]";
}
$Exceptions += $row
$row = new-object PSObject -Property @{
'Entry' = "0.0.0.0 chartbeat.com";
'Comment' = "#Unblocked SK 2020/03/15 [BeachBody]";
}
$Exceptions += $row
$row = new-object PSObject -Property @{
'Entry' = "0.0.0.0 ping.chartbeat.net";
'Comment' = "#Unblocked SK 2020/03/15 [BeachBody]";
}
$Exceptions += $row
$row = new-object PSObject -Property @{
'Entry' = "0.0.0.0 static.chartbeat.com";
'Comment' = "#Unblocked SK 2020/03/15 [BeachBody]";
}
$Exceptions += $row
$row = new-object PSObject -Property @{
'Entry' = "0.0.0.0 www.chartbeat.com";
'Comment' = "#Unblocked SK 2020/03/15 [BeachBody]";
}
$Exceptions += $row
$row = new-object PSObject -Property @{
'Entry' = "0.0.0.0 adsapi.chartbeat.com";
'Comment' = "#Unblocked SK 2020/03/15 [BeachBody]";
}
$Exceptions += $row
$row = new-object PSObject -Property @{
'Entry' = "0.0.0.0 bat.bing.com";
'Comment' = "#Unblocked SK 2020/03/15";
}
$Exceptions += $row
$row = new-object PSObject -Property @{
'Entry' = "0.0.0.0 metrics.beachbody.com";
'Comment' = "#Unblocked SK 2020/03/15 [BeachBody]";
}
$Exceptions += $row
$row = new-object PSObject -Property @{
'Entry' = "0.0.0.0 chartbeat.net";
'Comment' = "#Unblocked SK 2020/03/15 [BeachBody]";
}
$Exceptions += $row
$row = new-object PSObject -Property @{
'Entry' = "0.0.0.0 metrics.teambeachbody.com";
'Comment' = "#Unblocked SK 2020/05/26 [BeachBody]";
}
$Exceptions += $row
$row = new-object PSObject -Property @{
'Entry' = "0.0.0.0 partnerad.l.doubleclick.net";
'Comment' = "#Unblocked SK 2021/10/26 [Paramount+]";
}
$Exceptions += $row
#endregion
#region Comment out exceptions from above list. TODO: Figure out a way to make this into a loop...
$HostsFileContent += $StevenBlackHosts.Content
$1 = $HostsFileContent.replace($Exceptions[0].Entry, "#$($Exceptions[0].Entry) $($Exceptions[0].Comment)")
$2 = $1.replace($Exceptions[1].Entry, "#$($Exceptions[1].Entry) $($Exceptions[1].Comment)")
$3 = $2.replace($Exceptions[2].Entry, "#$($Exceptions[2].Entry) $($Exceptions[2].Comment)")
$4 = $3.replace($Exceptions[3].Entry, "#$($Exceptions[3].Entry) $($Exceptions[3].Comment)")
$5 = $4.replace($Exceptions[4].Entry, "#$($Exceptions[4].Entry) $($Exceptions[4].Comment)")
$6 = $5.replace($Exceptions[5].Entry, "#$($Exceptions[5].Entry) $($Exceptions[5].Comment)")
$7 = $6.replace($Exceptions[6].Entry, "#$($Exceptions[6].Entry) $($Exceptions[6].Comment)")
$8 = $7.replace($Exceptions[7].Entry, "#$($Exceptions[7].Entry) $($Exceptions[7].Comment)")
$9 = $8.replace($Exceptions[8].Entry, "#$($Exceptions[8].Entry) $($Exceptions[8].Comment)")
$10 = $9.replace($Exceptions[9].Entry, "#$($Exceptions[9].Entry) $($Exceptions[9].Comment)")
$11 = $10.replace($Exceptions[10].Entry, "#$($Exceptions[10].Entry) $($Exceptions[10].Comment)")
$12 = $11.replace($Exceptions[11].Entry, "#$($Exceptions[11].Entry) $($Exceptions[11].Comment)")
$13 = $12.replace($Exceptions[12].Entry, "#$($Exceptions[12].Entry) $($Exceptions[12].Comment)")
$14 = $13.replace($Exceptions[13].Entry, "#$($Exceptions[13].Entry) $($Exceptions[13].Comment)")
$14|out-file $HostsFile
#endregion
"# End of entries inserted by StevenBlack hosts ########################################################################################################################################"|out-file $HostsFile -Append
#region YouTube Ads (not using due to being too unreliable)
<# "#region########################################################################################################################################" |out-file $HostsFile -Append
"# Start of YouTube ad server list" |out-file $HostsFile -Append
foreach($line in $YouTubeAds.Content){
if($line -match "#"){
$line | out-file $HostsFile -Append
}else{
"0.0.0.0 $($line)" | out-file $HostsFile -Append
}
}
"# End of entries inserted by YouTube ad server list ########################################################################################################################################"|out-file $HostsFile -Append
#>
#endregion
#region Smart TVs (some are shared between the two but each contain some unique/exclusive entries)
"#region########################################################################################################################################" |out-file $HostsFile -Append
"# Start of Smart TV server list" |out-file $HostsFile -Append
foreach($line in $SmartTV1.Content){
if($line -match "#"){
$line | out-file $HostsFile -Append
}else{
"0.0.0.0 $($line)" | out-file $HostsFile -Append
}
}
foreach($line in $SmartTV2.Content){
if($line -match "#"){
$line | out-file $HostsFile -Append
}else{
"0.0.0.0 $($line)" | out-file $HostsFile -Append
}
}
"# End of entries inserted by Smart TV server list ########################################################################################################################################"|out-file $HostsFile -Append
#endregion
#endregion