Загрузка...

C # | BlockNet - Blocking Internet Access

Thread in C# created by Грут_inactive2721729 Apr 28, 2020. 242 views

  1. Грут_inactive2721729
    Грут_inactive2721729 Topic starter Apr 28, 2020 Banned 70 Oct 23, 2019
    Не позволит пользователю выйти на какой-либо интернет ресурс путём блокировки через реестр.
    После перехода на какой-нибудь ресурс пользователь увидит вот такое вот сообщение:
    [IMG]
    Создадим класс NativeMethods.cs

    Code
    using System;
    using System.Runtime.InteropServices;

    internal static class NativeMethods
    {
    [DllImport("wininet.dll")]
    internal static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength);
    }
    Создадим класс BlockIE.cs


    Code
    using Microsoft.Win32;
    using System;
    using System.IO;
    using System.Security;

    public class BlockIE
    {
    private enum INTERNET_OPTION : int
    {
    INTERNET_OPEN_TYPE_PROXY = 3,
    INTERNET_OPTION_REFRESH = 37,
    INTERNET_OPTION_PROXY = 38,
    INTERNET_OPTION_SETTINGS_CHANGED = 39,
    INTERNET_OPTION_VERSION = 40,
    INTERNET_OPTION_PER_CONNECTION_OPTION = 75
    }

    public static void Enabled(int block_internet)
    {
    string ProxyIP = "164.21.141.110:8888", ProxyEnable = "ProxyEnable", ProxyServer = "ProxyServer";
    const string IE = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";
    using (var hklmHive_x64 = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32))
    {
    using (RegistryKey runKey = hklmHive_x64.OpenSubKey(IE, Environment.Is64BitOperatingSystem ? true : false))
    {
    try
    {
    switch (block_internet)
    {
    case 0:
    runKey?.DeleteValue(ProxyEnable);
    runKey?.DeleteValue(ProxyServer);
    Console.WriteLine("Proxy Delete!");
    break;

    case 1:
    runKey?.SetValue(ProxyEnable, block_internet);
    runKey?.SetValue(ProxyServer, ProxyIP);
    Console.WriteLine("Proxy Installed");
    break;
    default:
    break;
    }
    NativeMethods.InternetSetOption(IntPtr.Zero, (int)INTERNET_OPTION.INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);
    NativeMethods.InternetSetOption(IntPtr.Zero, (int)INTERNET_OPTION.INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);
    }
    catch (Exception) { }
    }
    }
    }
    }
    Блокируем:

    Code
    BlockIE.Enabled(1);
    Разблокируем:

    Code
    BlockIE.Enabled(0);
     
  2. Melancholy
    Melancholy Apr 28, 2020 Banned 3460 May 31, 2018
    Давай-давай дальше лей c VLMI (не реклама)
     
  3. гоот_inactive2867561
    Заблокирую училке эл.жур:2011_like:
     
  4. Help
    Help Apr 28, 2020 469 May 12, 2017
    Смысл копировать эту хуйню ? Кому надо тот и нагуглит
     
Top
Loading...