Пример #1
0
        private static bool SetAdapter()
        {
            bool flag;
            ManagementBaseObject methodParameters = null;

            using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = (new ManagementObjectSearcher("select * from Win32_NetworkAdapterConfiguration where IPEnabled = 1 and Caption like '%Loopback Adapter%'")).Get().GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    ManagementObject current = (ManagementObject)enumerator.Current;
                    if (!(bool)current["IPEnabled"])
                    {
                        continue;
                    }
                    methodParameters = current.GetMethodParameters("EnableStatic");
                    methodParameters["IPAddress"]  = new string[] { "221.231.130.70" };
                    methodParameters["SubnetMask"] = new string[] { "255.255.255.0" };
                    current.InvokeMethod("EnableStatic", methodParameters, null);
                    NetworkAdapterInstaller.SendMessage("网卡信息设置成功!");
                    flag = true;
                    return(flag);
                }
                NetworkAdapterInstaller.SendErrorMessage("未找到可设置的虚拟网卡!");
                return(false);
            }
            return(flag);
        }
Пример #2
0
        private static bool ReleaseDevcon()
        {
            bool flag;

            Directory.CreateDirectory(NetworkAdapterInstaller.ARIESDIR);
            !Environment.Is64BitOperatingSystem;
            if (!FileUtil.FileMD5Validation((Environment.Is64BitOperatingSystem ? NetworkAdapterInstaller.X64MD5 : NetworkAdapterInstaller.X86MD5), NetworkAdapterInstaller.OUTFILE))
            {
                byte[] numArray = (Environment.Is64BitOperatingSystem ? Resource.devcon_x64 : Resource.devcon_x86);
                try
                {
                    using (FileStream fileStream = File.Create(NetworkAdapterInstaller.OUTFILE))
                    {
                        using (BinaryWriter binaryWriter = new BinaryWriter(fileStream))
                        {
                            binaryWriter.Write(numArray);
                        }
                    }
                    return(true);
                }
                catch (Exception exception)
                {
                    NetworkAdapterInstaller.SendErrorMessage("无法解压文件!");
                    flag = false;
                }
                return(flag);
            }
            return(true);
        }
Пример #3
0
 public static async void CheckAndInstallAdapter(Action <bool> callback)
 {
     await Task.Run(() => {
         if (NetworkAdapterInstaller.InstallMode != NetForwardMode.Adapter)
         {
             callback(NetworkAdapterInstaller.OpenSuperMode());
             return;
         }
         callback((!NetworkAdapterInstaller.ReleaseDevcon() ? false : NetworkAdapterInstaller.CheckAndOpenAdapter()));
     });
 }
Пример #4
0
        private static bool DisableRedirection()
        {
            NetworkAdapterInstaller.SendMessage("开始取消重定向..");
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("netsh int ip delete addr 1 221.231.130.70 \n");
            stringBuilder.Append("route delete 221.231.130.70");
            NetworkAdapterInstaller.RunCmd(stringBuilder.ToString(), new Action <Process>(NetworkAdapterInstaller.DEBUGWriteToConsole));
            NetworkAdapterInstaller.SendMessage("重定向已取消");
            return(true);
        }
Пример #5
0
 public static async void ChangeMode(NetForwardMode mode, Action <bool> callback)
 {
     await Task.Run(() => {
         NetworkAdapterInstaller.InstallMode = mode;
         if (mode != NetForwardMode.Adapter)
         {
             callback(NetworkAdapterInstaller.DisableLoopAdapters());
             return;
         }
         NetworkAdapterInstaller.SendMessage("正在启用虚拟网卡模式..");
         callback(NetworkAdapterInstaller.DisableRedirection());
     });
 }
Пример #6
0
        private static bool InstallAdapter()
        {
            NetworkAdapterInstaller.RunCmd("devcon.exe install %windir%/inf/netloop.inf *msloop", new Action <Process>(NetworkAdapterInstaller.DEBUGWriteToConsole));
            List <ManagementBaseObject> managementBaseObjects = NetworkAdapterInstaller.QueryInstalledLoopbackAdapters();

            if (managementBaseObjects.Count <= 0)
            {
                NetworkAdapterInstaller.SendErrorMessage("虚拟网卡安装失败!");
                return(false);
            }
            NetworkAdapterInstaller.SendMessage(string.Format("虚拟网卡安装成功:{0}", managementBaseObjects[0]["Caption"]));
            return(true);
        }
Пример #7
0
        private static bool EnableAdapter(string string_0)
        {
            List <ManagementBaseObject> managementBaseObjects = NetworkAdapterInstaller.QueryAdapterByPnp(string_0);

            if (managementBaseObjects.Count <= 0)
            {
                NetworkAdapterInstaller.SendErrorMessage(string.Format("未找到网卡{0},网卡启动失败", string_0));
                return(false);
            }
            NetworkAdapterInstaller.SendMessage(string.Format("找到虚拟网卡{0}", managementBaseObjects[0]["Caption"]));
            NetworkAdapterInstaller.RunCmd(string.Format("devcon.exe /r enable @{0}", string_0), new Action <Process>(NetworkAdapterInstaller.DEBUGWriteToConsole));
            return(true);
        }
Пример #8
0
 public static async void CloseNetwork()
 {
     await Task.Run(() => {
         try
         {
             NetworkAdapterInstaller.DisableRedirection();
             NetworkAdapterInstaller.DisableLoopAdapters();
         }
         catch
         {
         }
     });
 }
Пример #9
0
        private static bool Ping()
        {
            int num = 0;

            while (!NetworkAdapterInstaller.PingTest())
            {
                num++;
            }
            if (num >= 5)
            {
                return(NetworkAdapterInstaller.PingTest());
            }
            return(true);
        }
Пример #10
0
 public static async void ResetNetworkSettings()
 {
     await Task.Run(() => {
         NetworkAdapterInstaller.SendMessage("正在重置网络..,");
         NetworkAdapterInstaller.SendMessage("正在清空重定向设置...");
         int[] numArray = new int[] { 8484, 8600, 7575, 7576, 7577, 7578, 7579, 7580, 7581, 7582, 7583, 7584 };
         StringBuilder stringBuilder = new StringBuilder();
         int[] numArray1             = numArray;
         for (int i = 0; i < (int)numArray1.Length; i++)
         {
             int num = numArray1[i];
             stringBuilder.Append(string.Format("netsh interface portproxy delete v4tov4 {0} 221.231.130.70 \n", num));
             stringBuilder.Append(string.Format("netsh interface portproxy delete v4tov4 {0} 127.0.0.1 \n", num));
         }
         stringBuilder.Append("netsh int ip delete addr 1 221.231.130.70 \n");
         stringBuilder.Append("route delete 221.231.130.70");
         NetworkAdapterInstaller.RunCmd(stringBuilder.ToString(), null);
         NetworkAdapterInstaller.SendMessage("重定向设置已清除!");
         NetworkAdapterInstaller.DeleteAllLoopAdapters();
         NetworkAdapterInstaller.SendMessage("网络配置重置成功!");
     });
 }
Пример #11
0
        private static bool DeleteAllLoopAdapters()
        {
            NetworkAdapterInstaller.SendMessage("开始删除虚拟网卡");
            List <ManagementBaseObject> managementBaseObjects = NetworkAdapterInstaller.QuerySysinfo("Win32_NetworkAdapter", "Caption like '%Loopback Adapter%'");

            if (managementBaseObjects.Count <= 0)
            {
                NetworkAdapterInstaller.SendErrorMessage("没有可删除的虚拟网卡");
                return(true);
            }
            foreach (ManagementBaseObject managementBaseObject in managementBaseObjects)
            {
                NetworkAdapterInstaller.SendMessage(string.Format("找到虚拟网卡{0}", managementBaseObject["Name"]));
                NetworkAdapterInstaller.RunCmd(string.Format("devcon.exe /r remove @{0}", managementBaseObject["PNPDeviceID"]), new Action <Process>(NetworkAdapterInstaller.DEBUGWriteToConsole));
            }
            if (NetworkAdapterInstaller.QuerySysinfo("Win32_NetworkAdapter", "Caption like '%Loopback Adapter%'").Count == 0)
            {
                NetworkAdapterInstaller.SendMessage("删除成功!");
                return(false);
            }
            NetworkAdapterInstaller.SendMessage("删除失败!");
            return(false);
        }
Пример #12
0
        private static bool CheckAndOpenAdapter()
        {
            NetworkAdapterInstaller.SendMessage("开始检查虚拟网卡..");
            List <ManagementBaseObject> managementBaseObjects = NetworkAdapterInstaller.QueryInstalledLoopbackAdapters();

            if (managementBaseObjects.Count <= 0)
            {
                NetworkAdapterInstaller.SendMessage("未找到已安装的虚拟网卡...开始安装..");
                if (!NetworkAdapterInstaller.InstallAdapter())
                {
                    return(false);
                }
                NetworkAdapterInstaller.SendMessage("开始设置网卡信息");
                return(NetworkAdapterInstaller.SetAdapter());
            }
            if (managementBaseObjects.Count == 1)
            {
                if (NetworkAdapterInstaller.EnableAdapter(managementBaseObjects[0].Properties["PNPDeviceID"].Value.ToString()))
                {
                    NetworkAdapterInstaller.SendMessage("开始设置网卡信息");
                    return(NetworkAdapterInstaller.SetAdapter());
                }
                NetworkAdapterInstaller.SendErrorMessage("网卡启动失败!");
                return(false);
            }
            NetworkAdapterInstaller.SendMessage("找到多个虚拟网卡,处理中");
            for (int i = 0; i < managementBaseObjects.Count; i++)
            {
                if (i != 0)
                {
                    NetworkAdapterInstaller.DeleteAdapter(managementBaseObjects[i].Properties["PNPDeviceID"].Value.ToString());
                }
            }
            NetworkAdapterInstaller.SendMessage("开始设置网卡信息");
            return(NetworkAdapterInstaller.SetAdapter());
        }
Пример #13
0
 private static List <ManagementBaseObject> QueryInstalledLoopbackAdapters()
 {
     return(NetworkAdapterInstaller.QuerySysinfo("Win32_NetworkAdapter", "Caption like '%Loopback Adapter%'"));
 }