示例#1
0
        public static VAPUDomainAddress GetHoshEntry(String hostName)
        {
            VAPUDomainAddress vAPUDomainAddress = null;

            try
            {
                IPHostEntry          NameToIpAddress = Dns.GetHostEntry(hostName);
                List <VAPUIPAddress> lstIP           = new List <VAPUIPAddress>();
                foreach (IPAddress address in NameToIpAddress.AddressList)
                {
                    VAPUIPAddress vapuIp = new VAPUIPAddress();
                    vapuIp.IpAddress = address;
                    vapuIp.FilterId  = 0;
                    lstIP.Add(vapuIp);
                }

                vAPUDomainAddress                   = new VAPUDomainAddress();
                vAPUDomainAddress.DomainName        = hostName;
                vAPUDomainAddress.VapuIpAddressList = lstIP;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return(vAPUDomainAddress);
        }
示例#2
0
        static void Main(String[] args)
        {
            GUID providerKey = new GUID();

            providerKey.Data1 = 10;
            providerKey.Data2 = 11;
            providerKey.Data3 = 12;
            providerKey.Data4 = "123";

            GUID subLayerKey = new GUID();

            subLayerKey.Data1 = 13;
            subLayerKey.Data2 = 14;
            subLayerKey.Data3 = 15;
            subLayerKey.Data4 = "456";

            IntPtr engine     = new IntPtr();
            String domainName = "";
            ulong  result     = 0;

            result = NativeMethods.Install(ref providerKey, "Vista3Provider", ref subLayerKey, "Vista3SubLayer", ref engine);
            Console.WriteLine("CAI DAT ENGINE>>>" + result);

            List <VAPUDomainAddress> lstBlocked = new List <VAPUDomainAddress>();

            do
            {
                Console.WriteLine("Nhap domain name (nhap exit de thoat):");
                domainName = Console.ReadLine();
                VAPUDomainAddress vapuDomain = FilterUtil.GetHoshEntry(domainName);
                if (vapuDomain == null)
                {
                    if (!domainName.Equals("exit"))
                    {
                        Console.WriteLine("Khong tim thay domain");
                    }
                }
                else
                {
                    lstBlocked.Add(vapuDomain);

                    foreach (VAPUIPAddress ip in vapuDomain.VapuIpAddressList)
                    {
                        ulong filterId = 0;
                        result      = NativeMethods.AddFilter(ip.ToString(), engine, ref subLayerKey, out filterId);
                        ip.FilterId = filterId;
                        Console.WriteLine("ADD FILTER >>>" + ip.ToString() + ":" + result + ":" + ip.FilterId);
                    }
                }
            } while (!domainName.Equals("exit"));

            foreach (VAPUDomainAddress domain in lstBlocked)
            {
                foreach (VAPUIPAddress ip in domain.VapuIpAddressList)
                {
                    result = NativeMethods.RemoveFilter(engine, ip.FilterId);
                    Console.WriteLine("REMOVE FILTER >>>" + ip.ToString() + ":" + result + ":" + ip.FilterId);
                }
            }

            result = NativeMethods.Uninstall(ref providerKey, ref subLayerKey);
            Console.WriteLine("GO BO ENGINE>>>" + result);
            Console.ReadLine();
        }