-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock-Telemetry_v5_2.ps1
More file actions
1900 lines (1696 loc) · 82.6 KB
/
Copy pathBlock-Telemetry_v5_2.ps1
File metadata and controls
1900 lines (1696 loc) · 82.6 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# =====================================================================================
# BLOCAGE TELEMETRIE - FICHIER HOSTS WINDOWS
# VERSION 5.2
# =====================================================================================
# Ce script modifie UNIQUEMENT le fichier hosts Windows pour bloquer les domaines
# de télémétrie (collecte de données) des éditeurs majeurs.
#
# GARANTIES DE SÉCURITÉ :
# [S1] Sauvegarde automatique du fichier hosts avant toute modification
# [S2] Liste blanche stricte : aucun domaine fonctionnel n'est bloqué
# [S3] Rotation automatique des sauvegardes (conservation des 10 dernières)
# [S4] Mode simulation (DryRun) pour voir ce qui serait fait sans rien toucher
# [S5] Fonction de restauration complète intégrée (un seul choix au menu)
# [S6] Marqueur unique dans le fichier hosts pour identifier nos ajouts
# [S7] Aucune modification de registre, aucun service arrêté, aucun pilote touché
# [S8] Option "Mettre à jour" intégrée (restaure + ré-applique en une étape)
# [S9] Encodage UTF-8 AVEC BOM garanti (indispensable pour que PowerShell 5.1
# détecte l'UTF-8 ; sans BOM, PS 5.1 lit le fichier en ANSI et les
# caractères accentués corrompent le parsing — PowerShell 7 gère les deux)
# [S10] Vérification des doublons avant écriture (domaines déjà présents ignorés)
# [S11] Détection de conflits avec d'autres outils (CTT, etc.)
# [S12] Vérification d'intégrité du bloc actif (domaines attendus vs présents)
# [S13] Nettoyage des entrées externes optionnel (hors notre bloc)
#
# AMÉLIORATIONS v5.1 (architecture menu interactif conservée à l'identique) :
# [N1] -SelfTest : validations logiques en lecture seule (liste blanche, doublons,
# cohérence whitelist/blocage), lancé en paramètre CLI, sans toucher au hosts
# [N2] Export JSON automatique après chaque action réelle (Apply/Update/Restore)
# dans Rapports_Maintenance\Block-Telemetry, pour construire un historique
# structuré comme les autres scripts de la suite
# [N3] Indicateur d'intégrité affiché directement dans le menu principal (au lieu
# d'attendre l'option [A]) — même logique de comparaison, juste réutilisée
#
# CORRECTIF v5.2 :
# [C1] Ajout d'un BOM UTF-8 en tête de fichier. Sans lui, PowerShell 5.1 ouvrait
# le script en ANSI (faute de détection automatique de l'UTF-8), ce qui
# corrompait les caractères accentués et provoquait des erreurs de parsing
# (jetons inattendus autour des chaînes contenant des accents ou le tiret
# cadratin). PowerShell 7 n'était pas affecté, d'où le script fonctionnel
# uniquement sous pwsh avant ce correctif.
#
# CATÉGORIES COUVERTES :
# - Microsoft Télémétrie (Windows, Office, Defender, DiagTrack, Xbox, OneDrive)
# - Microsoft Copilot Télémétrie
# - Microsoft Edge Télémétrie
# - Google Analytics / Tracking
# - Adobe Analytics / Stats
# - Tracking tiers (Criteo, Taboola, Outbrain, Rubicon, PubMatic, OpenX, AMP...)
# - Rapports de crash (Sentry, Bugsnag)
# - Spotify Télémétrie
# - Brave Analytics
# - Mozilla / Firefox Télémétrie
# - NVIDIA Télémétrie
# - AMD Télémétrie
# - Discord Télémétrie
# - Steam / Valve Télémétrie
# - GOG Galaxy Télémétrie
#
# DOMAINES JAMAIS BLOQUES (liste blanche stricte) :
# - Activation, licences, authentification Adobe
# - Windows Update, activation Microsoft
# - NextDNS (service DNS critique)
# - Steam, Spotify, Brave, Mozilla (domaines fonctionnels)
# - NVIDIA / AMD (mises à jour pilotes)
# - GOG Galaxy (store et téléchargements)
# - Visual Studio Code (mises à jour)
# - Tout ce qui peut rendre une application inutilisable
# =====================================================================================
param(
[switch]$SelfTest # [N1] Validations logiques en lecture seule — pas besoin d'admin, sort avant l'élévation
)
#region AUTO-ELEVATION
# [N1] Le SelfTest est purement en lecture (hosts + comparaisons en mémoire) : on le
# traite avant l'élévation pour éviter une demande UAC inutile juste pour un contrôle.
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal(
[Security.Principal.WindowsIdentity]::GetCurrent()
)
if (-not $SelfTest -and -not $currentPrincipal.IsInRole(
[Security.Principal.WindowsBuiltInRole]::Administrator
)) {
# Utilise pwsh si disponible (PowerShell 7+), sinon powershell.exe (5.x)
$Shell = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh" } else { "powershell.exe" }
Start-Process $Shell `
-Verb RunAs `
-ArgumentList "-ExecutionPolicy Bypass -NoProfile -File `"$PSCommandPath`""
exit
}
if (-not $SelfTest) { Set-ExecutionPolicy Bypass -Scope Process -Force }
#endregion
#region INITIALISATION
$HostsPath = "$env:SystemRoot\System32\drivers\etc\hosts"
$BackupFolder = "$env:USERPROFILE\Desktop\Hosts_Backups"
$LogPath = "$env:USERPROFILE\Desktop\Block-Telemetry_Log.txt"
$Marker = "# === BLOC TELEMETRIE - Ne pas modifier manuellement ==="
$MarkerEnd = "# === FIN BLOC TELEMETRIE ==="
$Timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
$BackupMaxCount = 10 # Nombre maximum de sauvegardes à conserver
#endregion
#region DOMAINES TELEMETRIE
# =====================================================================================
# LISTE DES DOMAINES BLOQUES
#
# Règle de construction de cette liste :
# 1. Domaine connu comme collectant des données d'usage/télémétrie
# 2. NON nécessaire au fonctionnement de l'application
# 3. Vérifié : son blocage ne casse pas l'activation ni les licences
#
# ADOBE — Domaines de télémétrie/statistiques UNIQUEMENT
# NE SONT PAS dans cette liste (fonctionnels) :
# adobe.com, adobelogin.com, adobegenuine.com, adobejanus.com,
# adobeereg.com (enregistrement produit), lcs-cops.adobe.com,
# prod.adobegenuine.com, genuine.adobe.com
# =====================================================================================
$TelemetryDomains = [ordered]@{
# ------------------------------------------------------------------
# MICROSOFT — Télémétrie Windows et Office
# Sont EXCLUS de cette liste :
# windowsupdate.com, update.microsoft.com, msftconnecttest.com
# (nécessaires aux mises à jour et à la détection connectivité)
# ------------------------------------------------------------------
"Microsoft Telemetrie" = @(
"vortex.data.microsoft.com",
"vortex-win.data.microsoft.com",
"telecommand.telemetry.microsoft.com",
"telecommand.telemetry.microsoft.com.nsatc.net",
"oca.telemetry.microsoft.com",
"oca.telemetry.microsoft.com.nsatc.net",
"sqm.telemetry.microsoft.com",
"sqm.telemetry.microsoft.com.nsatc.net",
"watson.telemetry.microsoft.com",
"watson.telemetry.microsoft.com.nsatc.net",
"redir.metaservices.microsoft.com",
"choice.microsoft.com",
"choice.microsoft.com.nsatc.net",
"df.telemetry.microsoft.com",
"reports.wes.df.telemetry.microsoft.com",
"wes.df.telemetry.microsoft.com",
"services.wes.df.telemetry.microsoft.com",
"sqm.df.telemetry.microsoft.com",
"telemetry.microsoft.com",
"watson.microsoft.com",
"statsfe2.ws.microsoft.com",
"corpext.msitadfs.glbdns2.microsoft.com",
"compatexchange.cloudapp.net",
"cs1.wpc.v0cdn.net",
"a-0001.a-msedge.net",
"statsfe2.update.microsoft.com.akadns.net",
"sls.update.microsoft.com.akadns.net",
"fe2.update.microsoft.com.akadns.net",
"diagnostics.support.microsoft.com",
"corp.sts.microsoft.com",
"statsfe1.ws.microsoft.com",
"pre.footprintpredict.com",
"i1.services.social.microsoft.com",
"i1.services.social.microsoft.com.nsatc.net",
"feedback.windows.com",
"feedback.microsoft-hohm.com",
"feedback.search.microsoft.com",
# Télémétrie Office et pipeline ARIA
"mobile.pipe.aria.microsoft.com",
"pipe.aria.microsoft.com",
"browser.pipe.aria.microsoft.com",
"self.events.data.microsoft.com",
"v10.events.data.microsoft.com",
"v10c.events.data.microsoft.com",
"v20.events.data.microsoft.com",
"settings-win.data.microsoft.com",
"activity.windows.com",
"watson.live.com",
"ceuswatcab01.blob.core.windows.net",
"ceuswatcab02.blob.core.windows.net",
"eaus2watcab01.blob.core.windows.net",
"eaus2watcab02.blob.core.windows.net",
"weus2watcab01.blob.core.windows.net",
"weus2watcab02.blob.core.windows.net",
# Windows Defender — télémétrie cloud uniquement (pas la protection locale)
"spynet.microsoft.com",
"spynet2.microsoft.com",
"wdcp.microsoft.com",
"wdcpalt.microsoft.com",
"ssw.live.com",
# Publicité Windows / MSN / suggestions
"rad.msn.com",
"ads.msn.com",
"adnexus.net",
"ac3.msn.com",
"h1.msn.com",
# Cortana / Bing suggestions dans la barre de recherche
"bingapis.com",
"api.bing.com",
# DiagTrack — service "Expériences des utilisateurs connectés et télémétrie"
# Ce service (svchost DiagTrack) est le principal collecteur de données Windows
"watson.events.data.microsoft.com",
"umwatsonc.events.data.microsoft.com",
"v10-win.vortex.data.microsoft.com",
"v10.vortex-win.data.microsoft.com",
"functional.events.data.microsoft.com",
"umwatson.events.data.microsoft.com",
# Xbox / Game Bar — télémétrie gaming
"telemetry.xbox.com",
"data.microsoft.com",
"xbox.ipv6.microsoft.com",
"xboxexperiencesprod.experimentation.xboxlive.com",
"xaccount.microsoft.com",
# OneDrive — télémétrie (pas la synchronisation)
"telemetry.onedrive.com",
"onedrive.com.edgekey.net",
# Microsoft Teams — télémétrie (pas la communication)
"config.teams.microsoft.com",
"teams.events.data.microsoft.com"
)
# ------------------------------------------------------------------
# MICROSOFT COPILOT — Télémétrie et collecte de données
# Copilot envoie des données d'usage, requêtes et contexte
# vers les serveurs Microsoft/Bing. Ces endpoints sont purement
# analytiques — Copilot n'est pas bloqué fonctionnellement
# sur les machines qui l'utilisent volontairement.
# ------------------------------------------------------------------
"Microsoft Copilot Telemetrie" = @(
"copilot-proxy.microsoft.com",
"telemetry.bing.com",
"bat.bing.com",
"sydney.bing.com",
"copilot.microsoft.com",
"bing.com.edgekey.net",
"th.bing.com",
"r.bing.com",
"bat.r.msn.com",
"adsmeasurement.microsoft.com"
)
# Utile même si Edge est désinstallé sur certaines machines —
# WebView2 et les résidus Edge peuvent encore contacter ces endpoints.
# Sont EXCLUS : mise à jour Edge, WebView2 fonctionnel
# ------------------------------------------------------------------
"Microsoft Edge Telemetrie" = @(
"edge.microsoft.com",
"edgeassetservice.azureedge.net",
"ecs.microsoft.com",
"config.edge.skype.com",
"edge-mobile-static.azureedge.net",
"edgeservices.bing.com",
"assets.msn.com",
"ntp.msn.com"
)
# ------------------------------------------------------------------
# GOOGLE — Analytics et tracking tiers
# Sont EXCLUS : google.com, googleapis.com, gstatic.com
# (nécessaires à de nombreuses apps web et authentifications)
# ------------------------------------------------------------------
"Google Analytics / Tracking" = @(
"google-analytics.com",
"ssl.google-analytics.com",
"www.google-analytics.com",
"googletagmanager.com",
"www.googletagmanager.com",
"googletagservices.com",
"googlesyndication.com",
"pagead2.googlesyndication.com",
"adservice.google.com",
"doubleclick.net",
"stats.g.doubleclick.net",
"cm.g.doubleclick.net",
"googleadservices.com",
"www.googleadservices.com"
)
# ------------------------------------------------------------------
# ADOBE — Statistiques et analytics uniquement
# adobestats.io : collecte de statistiques d'usage des apps CC
# omtrdc.net : Adobe Analytics / Omniture (tracking comportemental)
# demdex.net : Adobe Audience Manager (profilage publicitaire)
# adobedtm.com : Adobe Dynamic Tag Manager (tracking marketing)
# NE SONT PAS dans cette liste (fonctionnels) :
# adobe.com, adobelogin.com, adobegenuine.com, lcs-cops.adobe.com
# ------------------------------------------------------------------
"Adobe Analytics / Stats" = @(
"adobestats.io",
"omtrdc.net",
"demdex.net",
"adobedtm.com",
"assets.adobedtm.com",
"adobe.tt.omtrdc.net",
"adobe.demdex.net",
"adobedc.demdex.net",
"sstats.adobe.com",
# Adobe Marketing Cloud / Advertising Cloud
"metrics.adobe.com",
"adobe-mc.omtrdc.net",
"cm.everesttech.net",
"everesttech.net",
"tubemogul.com",
"2o7.net"
)
# ------------------------------------------------------------------
# OUTILS DE TRACKING TIERS
# Ces domaines n'appartiennent à aucune app installée localement —
# ils sont uniquement chargés par des sites web ou des apps
# pour vous pister entre sessions.
# ------------------------------------------------------------------
"Tracking tiers" = @(
"scorecardresearch.com",
"b.scorecardresearch.com",
"pixel.quantserve.com",
"quantserve.com",
"ad.doubleclick.net",
"static.chartbeat.com",
"js.chartbeat.com",
"ping.chartbeat.net",
"cdn.speedcurve.com",
# Facebook / Meta tracking
"connect.facebook.net",
"graph.facebook.com",
"an.facebook.com",
# Amazon Ads
"aax.amazon-adsystem.com",
"c.amazon-adsystem.com",
# Twitter / X Ads
"ads-twitter.com",
"analytics.twitter.com",
# Hotjar (heatmaps comportementaux)
"static.hotjar.com",
"api.hotjar.com",
"insights.hotjar.com",
# Mixpanel
"api.mixpanel.com",
# Segment
"api.segment.io",
"cdn.segment.com",
# Criteo — retargeting publicitaire cross-site très agressif
"criteo.com",
"static.criteo.net",
"dis.criteo.com",
"rtax.criteo.com",
"gum.criteo.com",
# Taboola — contenu sponsorisé et tracking comportemental
"taboola.com",
"cdn.taboola.com",
"trc.taboola.com",
"nr-data.taboola.com",
# Outbrain — même catégorie que Taboola
"outbrain.com",
"amplify.outbrain.com",
"widgets.outbrain.com",
# Rubicon Project / Magnite — enchères publicitaires temps réel
"rubiconproject.com",
"fastlane.rubiconproject.com",
# PubMatic — plateforme SSP publicitaire
"pubmatic.com",
"ads.pubmatic.com",
# OpenX — enchères publicitaires
"openx.net",
"delivery.openx.net",
# Moat — mesure de visibilité des publicités (Oracle)
"moatads.com",
"z.moatads.com",
# Google AMP — proxy Google qui collecte données de navigation
"ampproject.org",
"cdn.ampproject.org",
# LinkedIn Insight Tag — tracking B2B
"snap.licdn.com",
"platform.linkedin.com"
)
# ------------------------------------------------------------------
# COLLECTE D'ERREURS / CRASH REPORTS
# Sentry.io, Bugsnag : envoient les stack traces et données système
# lors de plantages d'applications. Informatif mais intrusif.
# Note : peut réduire la qualité des correctifs d'applications.
# ------------------------------------------------------------------
"Rapports de crash" = @(
"sentry.io",
"o1383653.ingest.sentry.io",
"o987771.ingest.us.sentry.io",
"browser.sentry-cdn.com",
"bugsnag.com",
"notify.bugsnag.com",
"sessions.bugsnag.com",
"app.bugsnag.com"
)
# ------------------------------------------------------------------
# SPOTIFY — Télémétrie et analytics uniquement
# Sont EXCLUS : *.spotify.com (streaming, login, API),
# *.scdn.co (CDN musique), accounts.spotify.com, api.spotify.com
# ------------------------------------------------------------------
"Spotify Telemetrie" = @(
"log.spotify.com",
"crashdump.spotify.com",
"audio-ec.spotify.com",
"heads4-ash2-accesspoint.ap.spotify.com",
"heads4-accesspoint.ap.spotify.com",
"cpapi.spotify.com"
)
# ------------------------------------------------------------------
# BRAVE — Analytics et expérimentations
# "Privacy-Preserving Product Analytics" (P3A) : même agrégé,
# c'est de la collecte de données d'usage envoyée à Brave Software.
# Web Discovery Project (WDP) : collecte de données de recherche/pages
# pour améliorer Brave Search (feature opt-in, désactivée via policy
# BraveWebDiscoveryEnabled=0 ; ces domaines n'ont aucune autre fonction,
# donc blocage hosts sans risque).
# Sont EXCLUS : mise à jour Brave, composants de sécurité,
# laptop-updates.brave.com (usage ping MAIS aussi canal de mise à
# jour du binaire — ne jamais bloquer, cf. BraveStatsPingEnabled
# géré uniquement via policy registre)
# ------------------------------------------------------------------
"Brave Analytics" = @(
"p3a.brave.com",
"p2a.brave.com",
"cr.brave.com",
"variations.brave.com",
"star-randsrv.bsg.brave.com",
"patterns.wdp.brave.com",
"collector.wdp.brave.com"
)
# ------------------------------------------------------------------
# MOZILLA / FIREFOX — Télémétrie et expérimentations
# LibreWolf désactive déjà la plupart via sa config interne,
# mais ces endpoints résiduels peuvent encore être contactés.
# Sont EXCLUS : addons.mozilla.org, safebrowsing (sécurité)
# ------------------------------------------------------------------
"Mozilla / Firefox Telemetrie" = @(
"telemetry.mozilla.org",
"incoming.telemetry.mozilla.org",
"crash-stats.mozilla.com",
"normandy.cdn.mozilla.net",
"normandy-cdn.mozilla.net",
"experimenter.mozilla.org",
"firefox.settings.services.mozilla.com",
"coverage.mozilla.org",
"mozac.telemetry.mozilla.org"
)
# ------------------------------------------------------------------
# NVIDIA — Télémétrie GeForce Experience / NVIDIA App
# Sont EXCLUS : mise à jour pilotes, GeForce NOW (streaming)
# ------------------------------------------------------------------
"NVIDIA Telemetrie" = @(
"telemetry.nvidia.com",
"gfe.nvidia.com",
"events.gfe.nvidia.com",
"telemetry.gfe.nvidia.com",
"crashreport.nvidia.com",
"ota.nvidia.com",
"services.gfe.nvidia.com",
"accounts.nvgs.nvidia.com",
"notifications.nvgs.nvidia.cn"
)
# ------------------------------------------------------------------
# AMD — Télémétrie AMD Software / Adrenalin
# Sont EXCLUS : mise à jour pilotes AMD
# ------------------------------------------------------------------
"AMD Telemetrie" = @(
"telemetry.amd.com",
"crashreport.amd.com",
"analytics.amd.com",
"amd-detect.amd.com",
"dc.services.visualstudio.com"
)
# ------------------------------------------------------------------
# DISCORD — Télémétrie et analytics
# Discord envoie des données d'usage détaillées (Science API)
# Sont EXCLUS : discord.com (fonctionnel), gateway.discord.gg (chat)
# ------------------------------------------------------------------
"Discord Telemetrie" = @(
"discord-attachments-uploads-prd.storage.googleapis.com",
"click.discord.com",
"crash.discord.com"
# sentry.io retiré d'ici : déjà couvert par la catégorie "Rapports de crash".
# Get-DomainsToBlock ne dédoublonne QUE par rapport aux entrées déjà présentes
# dans le hosts hors de notre bloc — pas entre catégories de cette liste elle-même.
)
# ------------------------------------------------------------------
# STEAM / VALVE — Télémétrie et analytics
# Sont EXCLUS : steampowered.com, steamcommunity.com, vac.valve.net
# (plateforme, anti-cheat et téléchargements jeux)
# ------------------------------------------------------------------
"Steam / Valve Telemetrie" = @(
"media.steampowered.com",
"clientconfig.akamai.steamstatic.com",
"steamstat.us",
"ingest.sentry.io" # doublon Sentry géré automatiquement
)
# ------------------------------------------------------------------
# GOG GALAXY — Télémétrie et analytics
# Sont EXCLUS : gog.com (store), cdn.gog.com (téléchargements)
# ------------------------------------------------------------------
"GOG Galaxy Telemetrie" = @(
"telemetry.gog.com",
"analytics.gog.com",
"metrics.gog.com",
"reporting.gog.com"
)
}
# =====================================================================================
# LISTE BLANCHE ABSOLUE — Ces domaines ne seront JAMAIS bloqués
# même s'ils apparaissent dans $TelemetryDomains par erreur
# =====================================================================================
$AbsoluteWhitelist = @(
# Adobe — activation et licences exactes
"activate.adobe.com",
"practivate.adobe.com",
"ereg.adobe.com",
"genuine.adobe.com",
"prod.adobegenuine.com",
"adobegenuine.com",
"adobejanus.com",
"adobeereg.com",
"lcs-cops.adobe.com",
"ims-na1.adobelogin.com",
"adobelogin.com",
"cc-api-data.adobe.io",
"services.adobe.com",
# Microsoft — mises à jour et activation exactes
"windowsupdate.com",
"update.microsoft.com",
"download.microsoft.com",
"go.microsoft.com",
"msftconnecttest.com",
"msftncsi.com",
"dns.msftncsi.com",
"login.microsoftonline.com",
"login.live.com",
"activation.sls.microsoft.com",
# Microsoft Edge WebView2 — composant système
"msedge.net",
# OneDrive — synchronisation fonctionnelle
"onedrive.live.com",
"storage.live.com",
# Xbox — authentification fonctionnelle
"xboxlive.com",
# Microsoft Teams — communication fonctionnelle
"teams.microsoft.com",
# NextDNS — service DNS critique
"nextdns.io",
"dns.nextdns.io",
"link.nextdns.io",
# Spotify — streaming, authentification, API
"accounts.spotify.com",
"api.spotify.com",
"apresolve.spotify.com",
"dealer.spotify.com",
"scdn.co",
"spotifycdn.com",
# Brave — mises à jour et sécurité
"updates.bravesoftware.com",
"safebrowsing.brave.com",
"go-updater.brave.com",
# Mozilla — mises à jour et sécurité
"addons.mozilla.org",
"safebrowsing.googleapis.com",
"aus5.mozilla.org",
"balrog-admin.stage.mozaws.net",
# Steam — plateforme et anti-cheat
"steampowered.com",
"steamcommunity.com",
"steamgames.com",
"steamusercontent.com",
"steamcdn-a.akamaihd.net",
"vac.valve.net",
# NVIDIA — mises à jour pilotes
"download.nvidia.com",
"international.download.nvidia.com",
"gfwsl.geforce.com",
# AMD — mises à jour pilotes
"drivers.amd.com",
"radeon.com",
# Epic Games — store et launcher (non utilisé ici, gardé en liste blanche par précaution :
# coût nul, évite un blocage accidentel si réutilisé sur une autre machine ou étendu plus tard)
"launcher.epicgames.com",
"store.epicgames.com",
"www.epicgames.com",
"unrealengine.com",
# Discord — communication
"discord.com",
"discordapp.com",
"discord.gg",
"gateway.discord.gg",
"dl.discordapp.net",
# GOG — store et téléchargements
"cdn.gog.com",
"galaxy-client.gog.com",
"store.gog.com",
"www.gog.com",
# Visual Studio Code — mises à jour
"update.code.visualstudio.com",
"marketplace.visualstudio.com",
# DNS et infrastructure réseau
"localhost"
)
#endregion
#region FONCTIONS
function Write-Log {
param([string]$Message, [string]$Level = "INFO")
$Line = "[$((Get-Date).ToString('HH:mm:ss'))] [$Level] $Message"
Add-Content -Path $LogPath -Value $Line -Encoding UTF8 -ErrorAction SilentlyContinue
}
# [N2] Snapshot JSON après chaque action réelle (Apply/Update/Restore), pour construire
# un historique structuré comme les autres scripts de la suite. N'est jamais appelée en
# mode simulation (DryRun) puisqu'aucun état réel n'a changé.
function Write-JsonSnapshot {
param(
[string]$Action, # "Application", "Mise à jour", "Restauration"
[int]$TotalDomains = 0,
[int]$SkippedCount = 0,
[array]$Categories = @()
)
try {
$ReportFolder = "$env:USERPROFILE\Desktop\Rapports_Maintenance\Block-Telemetry"
if (-not (Test-Path $ReportFolder)) {
New-Item -ItemType Directory -Path $ReportFolder -Force | Out-Null
}
$PerCategory = $Categories | Group-Object Category | ForEach-Object {
[PSCustomObject]@{ Categorie = $_.Name; Domaines = $_.Count }
}
$Snapshot = [PSCustomObject]@{
Timestamp = Get-Date -Format "dd/MM/yyyy HH:mm:ss"
Action = $Action
TotalDomaines = $TotalDomains
Ignores = $SkippedCount
ParCategorie = $PerCategory
}
$JsonPath = Join-Path $ReportFolder "Block-Telemetry_$(Get-Date -Format 'yyyy-MM-dd_HH-mm-ss').json"
$Snapshot | ConvertTo-Json -Depth 3 | Out-File $JsonPath -Encoding UTF8 -Force
}
catch {
# Non-bloquant : un échec d'export JSON ne doit jamais faire échouer l'action réelle
Write-Log "Échec export JSON snapshot : $_" "AVERT"
}
}
function Write-Header {
param([string]$Text)
Write-Host ""
Write-Host " $Text" -ForegroundColor Cyan
Write-Host " $('-' * $Text.Length)" -ForegroundColor DarkCyan
}
# Écriture UTF-8 sans BOM, compatible PowerShell 5 et 7
function Write-UTF8NoBOM {
param([string]$Path, [string[]]$Lines)
$Encoding = New-Object System.Text.UTF8Encoding($false) # $false = pas de BOM
[System.IO.File]::WriteAllLines($Path, $Lines, $Encoding)
}
function Backup-Hosts {
try {
if (-not (Test-Path $BackupFolder)) {
New-Item -ItemType Directory -Path $BackupFolder -Force | Out-Null
}
$BackupPath = Join-Path $BackupFolder "hosts_backup_$Timestamp"
Copy-Item -Path $HostsPath -Destination $BackupPath -Force
Write-Host " [OK] Sauvegarde : $BackupPath" -ForegroundColor Green
Write-Log "Sauvegarde créée : $BackupPath"
# Rotation : supprimer les sauvegardes excédentaires (les plus anciennes)
$AllBackups = Get-ChildItem -Path $BackupFolder -Filter "hosts_backup_*" |
Sort-Object LastWriteTime -Descending
if ($AllBackups.Count -gt $BackupMaxCount) {
$ToDelete = $AllBackups | Select-Object -Skip $BackupMaxCount
foreach ($Old in $ToDelete) {
Remove-Item -Path $Old.FullName -Force -ErrorAction SilentlyContinue
Write-Log "Ancienne sauvegarde supprimée (rotation) : $($Old.Name)"
}
Write-Host " [OK] Rotation : $($ToDelete.Count) ancienne(s) sauvegarde(s) supprimée(s)" -ForegroundColor DarkGray
}
return $BackupPath
}
catch {
Write-Host " [ERREUR] Impossible de créer la sauvegarde : $_" -ForegroundColor Red
Write-Log "Erreur sauvegarde : $_" "ERREUR"
return $null
}
}
function Get-CurrentHostsContent {
try {
return Get-Content -Path $HostsPath -Encoding UTF8 -ErrorAction Stop
}
catch {
Write-Host " [ERREUR] Impossible de lire le fichier hosts : $_" -ForegroundColor Red
return $null
}
}
function Test-IsAlreadyBlocked {
# Vérifie si notre marqueur est déjà présent dans le fichier hosts
$Content = Get-CurrentHostsContent
if (-not $Content) { return $false }
return ($Content | Where-Object { $_ -match [regex]::Escape($Marker) }).Count -gt 0
}
function Get-DomainsToBlock {
# Retourne la liste plate de tous les domaines à bloquer
# en excluant ceux présents dans la liste blanche absolue
# et ceux déjà présents dans le fichier hosts (anti-doublons)
# Lire les domaines déjà présents dans le hosts (hors notre bloc)
$ExistingHosts = @{}
$HostsContent = Get-CurrentHostsContent
if ($HostsContent) {
$InOurBlock = $false
foreach ($Line in $HostsContent) {
if ($Line -match [regex]::Escape($Marker)) { $InOurBlock = $true; continue }
if ($Line -match [regex]::Escape($MarkerEnd)) { $InOurBlock = $false; continue }
if (-not $InOurBlock -and $Line -match '^0\.0\.0\.0\s+(.+)$') {
$ExistingHosts[$Matches[1].Trim().ToLower()] = $true
}
}
}
$All = @()
foreach ($Category in $TelemetryDomains.Keys) {
foreach ($Domain in $TelemetryDomains[$Category]) {
$Domain = $Domain.ToLower().Trim()
# Vérification liste blanche — comparaison exacte uniquement
# (pas de EndsWith pour éviter de bloquer tous les sous-domaines)
$IsWhitelisted = $AbsoluteWhitelist -contains $Domain
if ($IsWhitelisted) { continue }
# Vérification doublon (déjà présent dans le hosts hors notre bloc)
$IsDuplicate = $ExistingHosts.ContainsKey($Domain)
$All += [PSCustomObject]@{
Domain = $Domain
Category = $Category
IsDuplicate = $IsDuplicate
}
}
}
return $All
}
function Remove-OurBlocksFromHosts {
# Supprime uniquement le bloc que nous avons ajouté
# Le reste du fichier hosts est préservé tel quel
try {
$Lines = Get-CurrentHostsContent
if (-not $Lines) { return $false }
$InOurBlock = $false
$CleanLines = @()
foreach ($Line in $Lines) {
if ($Line -match [regex]::Escape($Marker)) {
$InOurBlock = $true
continue
}
if ($Line -match [regex]::Escape($MarkerEnd)) {
$InOurBlock = $false
continue
}
if (-not $InOurBlock) {
$CleanLines += $Line
}
}
# Supprimer les lignes vides en fin de fichier (cosmétique)
while ($CleanLines.Count -gt 0 -and $CleanLines[-1].Trim() -eq "") {
$CleanLines = $CleanLines[0..($CleanLines.Count - 2)]
}
Write-UTF8NoBOM -Path $HostsPath -Lines $CleanLines
return $true
}
catch {
Write-Host " [ERREUR] Impossible de nettoyer le fichier hosts : $_" -ForegroundColor Red
Write-Log "Erreur nettoyage hosts : $_" "ERREUR"
return $false
}
}
function Flush-DNSCache {
try {
ipconfig /flushdns | Out-Null
Write-Host " [OK] Cache DNS vidé" -ForegroundColor Green
Write-Log "Cache DNS vidé"
}
catch {
Write-Host " [AVERT] Impossible de vider le cache DNS : $_" -ForegroundColor Yellow
}
}
#endregion
#region AFFICHAGE MENU
function Show-Menu {
Clear-Host
Write-Host ""
Write-Host " ============================================================" -ForegroundColor Cyan
Write-Host " BLOCAGE TELEMETRIE - FICHIER HOSTS WINDOWS v5.2" -ForegroundColor Cyan
Write-Host " ============================================================" -ForegroundColor Cyan
Write-Host ""
# Statut actuel + statistiques
$AlreadyBlocked = Test-IsAlreadyBlocked
if ($AlreadyBlocked) {
# Compter les domaines actifs dans le bloc
$ActiveCount = (Get-CurrentHostsContent | Where-Object { $_ -match '^0\.0\.0\.0 ' }).Count
$BlockDate = (Get-CurrentHostsContent | Where-Object { $_ -match '^# Généré le ' } | Select-Object -First 1) -replace '^# Généré le ',''
Write-Host " Statut : " -NoNewline
Write-Host "BLOCAGE ACTIF" -ForegroundColor Green -NoNewline
Write-Host " ($ActiveCount domaines)" -ForegroundColor DarkGreen
if ($BlockDate) {
Write-Host " Appliqué le : $BlockDate" -ForegroundColor DarkGray
}
# [N3] Indicateur d'intégrité compact — réutilise Get-IntegrityStatus (lecture seule,
# même logique que l'option [A]) pour éviter d'attendre une vérification manuelle
$IntegrityStatus = Get-IntegrityStatus
if ($IntegrityStatus.Missing.Count -eq 0 -and $IntegrityStatus.Extra.Count -eq 0) {
Write-Host " Intégrité : " -NoNewline
Write-Host "OK — bloc complet et à jour" -ForegroundColor DarkGreen
}
else {
Write-Host " Intégrité : " -NoNewline
Write-Host "$($IntegrityStatus.Missing.Count) manquant(s), $($IntegrityStatus.Extra.Count) en trop — voir option [A]" -ForegroundColor Yellow
}
}
else {
Write-Host " Statut : " -NoNewline
Write-Host "Aucun blocage appliqué" -ForegroundColor Gray
$TotalDomains = (Get-DomainsToBlock | Where-Object { -not $_.IsDuplicate }).Count
Write-Host " Domaines disponibles : $TotalDomains" -ForegroundColor DarkGray
}
Write-Host ""
Write-Host " [1] Voir les domaines qui seront bloqués" -ForegroundColor White
Write-Host " [2] Appliquer le blocage" -ForegroundColor Yellow
Write-Host " [3] Mettre à jour la liste (restaurer + ré-appliquer)" -ForegroundColor Yellow
Write-Host " [4] Simuler sans modifier (DryRun)" -ForegroundColor DarkYellow
Write-Host " [5] RESTAURER le fichier hosts original" -ForegroundColor Red
Write-Host " [6] Voir les sauvegardes disponibles" -ForegroundColor Gray
Write-Host " [7] Vider le cache DNS manuellement" -ForegroundColor Gray
Write-Host " [8] Générer un rapport HTML" -ForegroundColor Cyan
Write-Host " [9] Vérifier les conflits (autres outils)" -ForegroundColor Cyan
Write-Host " [A] Vérifier l'intégrité du bloc actif" -ForegroundColor Cyan
Write-Host " [E] Exporter la liste active (.txt)" -ForegroundColor DarkGray
Write-Host " [Q] Quitter" -ForegroundColor DarkGray
Write-Host ""
Write-Host " Choix : " -NoNewline
return (Read-Host)
}
#endregion
#region ACTION : AFFICHER LES DOMAINES
function Show-DomainList {
Clear-Host
Write-Host ""
Write-Host " ============================================================" -ForegroundColor Cyan
Write-Host " DOMAINES QUI SERONT BLOQUES" -ForegroundColor Cyan
Write-Host " ============================================================" -ForegroundColor Cyan
$Domains = Get-DomainsToBlock
$CurrentCategory = ""
$Total = 0
foreach ($Item in $Domains | Sort-Object Category, Domain) {
if ($Item.Category -ne $CurrentCategory) {
Write-Host ""
Write-Host " >> $($Item.Category)" -ForegroundColor Yellow
$CurrentCategory = $Item.Category
}
Write-Host " 0.0.0.0 $($Item.Domain)" -ForegroundColor Gray
$Total++
}
Write-Host ""
Write-Host " ────────────────────────────────────────────────────────────" -ForegroundColor DarkCyan
Write-Host " Total : $Total domaines" -ForegroundColor White
Write-Host ""
Write-Host " LISTE BLANCHE (jamais bloqués) :" -ForegroundColor Green
foreach ($Safe in $AbsoluteWhitelist | Select-Object -First 8) {
Write-Host " $Safe" -ForegroundColor DarkGreen
}
Write-Host " ... et $($AbsoluteWhitelist.Count - 8) autres domaines critiques" -ForegroundColor DarkGreen
Write-Host ""
Read-Host " Appuyez sur Entrée pour revenir au menu"
}
#endregion
#region ACTION : APPLIQUER LE BLOCAGE
function Apply-Blocking {
param(
[bool]$Simulation = $false,
[bool]$ForceUpdate = $false
)
Clear-Host
Write-Host ""
if ($Simulation) {
Write-Host " ============================================================" -ForegroundColor DarkYellow
Write-Host " MODE SIMULATION - Aucune modification ne sera effectuée" -ForegroundColor DarkYellow
Write-Host " ============================================================" -ForegroundColor DarkYellow
}
else {
Write-Host " ============================================================" -ForegroundColor Yellow
Write-Host " APPLICATION DU BLOCAGE" -ForegroundColor Yellow
Write-Host " ============================================================" -ForegroundColor Yellow
}
Write-Host ""
# Vérifier si déjà appliqué
if (-not $Simulation -and (Test-IsAlreadyBlocked)) {
if (-not $ForceUpdate) {
Write-Host " [INFO] Un blocage est déjà actif dans le fichier hosts." -ForegroundColor Cyan
Write-Host ""
Write-Host " Voulez-vous mettre à jour la liste (restaurer + ré-appliquer) ? (O/N) : " -NoNewline -ForegroundColor Yellow
$UpdAnswer = Read-Host
if ($UpdAnswer -notin @("O","o","oui","OUI","y","Y","yes","YES")) {
Write-Host " Annulé." -ForegroundColor Gray
Write-Host ""
Read-Host " Appuyez sur Entrée pour revenir au menu"
return
}
}
# Restauration silencieuse avant ré-application
Write-Header "Nettoyage du bloc existant avant mise à jour"
$BackupPath = Backup-Hosts
$null = Remove-OurBlocksFromHosts
Write-Host " [OK] Ancien bloc supprimé — ré-application en cours..." -ForegroundColor Green
Write-Log "Mise à jour : ancien bloc supprimé"
Write-Host ""
}
# Étape 1 : Sauvegarde
Write-Header "Étape 1/4 : Sauvegarde du fichier hosts actuel"
if (-not $Simulation) {
$BackupPath = Backup-Hosts
if (-not $BackupPath) {
Write-Host ""
Write-Host " [ERREUR FATALE] La sauvegarde a échoué." -ForegroundColor Red
Write-Host " Le blocage N'A PAS été appliqué par mesure de sécurité." -ForegroundColor Red
Write-Host ""
Read-Host " Appuyez sur Entrée pour revenir au menu"
return
}
}
else {
Write-Host " [SIMULATION] Sauvegarde dans : $BackupFolder\hosts_backup_$Timestamp" -ForegroundColor DarkYellow
}
# Étape 2 : Préparer les lignes à ajouter
Write-Header "Étape 2/4 : Préparation des règles de blocage"
$Domains = Get-DomainsToBlock
$BlockLines = @()
$BlockLines += ""
$BlockLines += $Marker