Exemplo n.º 1
0
        /// <summary>
        /// Method that instantiates a Dialog to set the addresses.
        /// </summary>
        /// <param name="netParamForm">Reference to the dialog form</param>
        private void showNetworkParametersFromDialog(NetworkParametersForm netParamForm)
        {
            string adapter;
            string ip;
            string mask;
            string gateway;
            string mac;

            try {
                var      netProperties     = new Dictionary <string, string>();
                string[] networkProperties = System.IO.File.ReadAllLines("C:\\\\Temp\\netParams.txt");
                if (networkProperties.Length != 0)
                {
                    foreach (var row in networkProperties)
                    {
                        netProperties.Add(row.Split('=')[0], row.Split('=')[1]);
                    }
                    ip = netProperties["ip"];
                    netParamForm.setIPAddress(ip);
                    mask = netProperties["subnet mask"];
                    netParamForm.setMaskAddress(mask);
                    gateway = netProperties["default gateway"];
                    netParamForm.setGatewayAddress(gateway);
                }
                adapter = "TAP-Win32 Adapter V9";
                netParamForm.setAdapterDescriptor(adapter);
            }
            catch (Exception ex) {
                adapter = "TAP-Win32 Adapter V9";
                netParamForm.setAdapterDescriptor(adapter);
                ip      = null;
                mask    = null;
                gateway = null;
                mac     = null;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method that instantiates a Dialog to set the addresses.
        /// </summary>
        /// <param name="netParamForm">Reference to the dialog form</param>
        private void showNetworkParametersFromDialog(NetworkParametersForm netParamForm)
        {
            string adapter;
            string ip;
            string mask;
            string gateway;
            string mac;

            try {
                var netProperties = new Dictionary<string,string>();
                string[] networkProperties = System.IO.File.ReadAllLines("C:\\\\Temp\\netParams.txt");
                if(networkProperties.Length != 0) {
                    foreach(var row in networkProperties) {
                        netProperties.Add(row.Split('=')[0],row.Split('=')[1]);
                    }
                    ip = netProperties["ip"];
                    netParamForm.setIPAddress(ip);
                    mask = netProperties["subnet mask"];
                    netParamForm.setMaskAddress(mask);
                    gateway = netProperties["default gateway"];
                    netParamForm.setGatewayAddress(gateway);
                }
                adapter = "TAP-Win32 Adapter V9";
                netParamForm.setAdapterDescriptor(adapter);

            }
            catch(Exception ex) {
                adapter = "TAP-Win32 Adapter V9";
                netParamForm.setAdapterDescriptor(adapter);
                ip = null;
                mask = null;
                gateway = null;
                mac = null;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Method that tries to set the ip, subnet mask, default gateway 
        /// and mac addresses using the .exe file specified as paramerer. 
        /// The exec file set also the MTU registry to 1500 and the 
        /// AllowNonAdmin registy to 1.
        /// </summary>
        /// <param name="execTestFile">Executable file to change the addresses</param>
        /// <returns>0 if everything went fine, a negative number otherwise</returns>
        private int tryAddressesSetting(string execTestFile)
        {
            int tapTestResult = -4;
            NetworkParametersForm netParamForm = new NetworkParametersForm();
            showNetworkParametersFromDialog(netParamForm);
            DialogResult dr = netParamForm.ShowDialog();
            if(dr == System.Windows.Forms.DialogResult.OK) {
                string adapterDescriptor = netParamForm.getAdapterDescriptor();
                string ip = netParamForm.getIPAddress();
                string mask = netParamForm.getMaskAddress();
                string gateway = netParamForm.getGatewayAddress();
                string mac = netParamForm.getMACAddress();
                string ipOptions;
                if(String.IsNullOrEmpty(gateway)) {
                    ipOptions = "-updateIP -d \"" + adapterDescriptor + "\" -ip " + ip + " -mask " + mask;
                }
                else {
                    ipOptions = "-updateIP -d \"" + adapterDescriptor + "\" -ip " + ip + " -mask " + mask + " -gateway " + gateway;
                }
                Process setIPProcess = Process.Start(execTestFile,ipOptions);
                setIPProcess.WaitForExit();
                tapTestResult = setIPProcess.ExitCode;
                if(tapTestResult != 0) {
                    TapInterfaceTestResDialog netParametersDialog = new TapInterfaceTestResDialog("TAP INTERFACE TEST - NETWORK PARAMERS SETTING" +
                        System.Environment.NewLine + "The ip, netmask and gateway addresses have not been setted properly. " +
                        System.Environment.NewLine + "This won't stop the installation process but it will preclude " +
                        System.Environment.NewLine + "the correct netproxy working.",true,false);
                    netParametersDialog.ShowDialog();
                    netParametersDialog.Dispose();
                    return -1;
                }
                string macOptions = "-updateMac -d \"" + adapterDescriptor + "\" -a " + mac;
                Process setMacProcess = Process.Start(execTestFile,macOptions);
                setMacProcess.WaitForExit();
                tapTestResult = setMacProcess.ExitCode;
                if(tapTestResult != 0) {
                    TapInterfaceTestResDialog netParametersDialog = new TapInterfaceTestResDialog("TAP INTERFACE TEST - NETWORK PARAMERS SETTING" +
                        System.Environment.NewLine + "The mac address has not been setted properly. " +
                        System.Environment.NewLine + "This won't stop the installation process but it will preclude " +
                        System.Environment.NewLine + "the correct netproxy working.",true,false);
                    netParametersDialog.ShowDialog();
                    netParametersDialog.Dispose();
                    return -2;
                }

                // Run again the test to check the network parameters for the just installed tap interface
                Process tapTestProcess = Process.Start(execTestFile,"-testtap");
                tapTestProcess.WaitForExit();
                tapTestResult = tapTestProcess.ExitCode;
            }
            if((dr == System.Windows.Forms.DialogResult.Cancel) || (tapTestResult == -4)) {
                //netParamForm.Dispose();
                TapInterfaceTestResDialog netParametersDialog = new TapInterfaceTestResDialog("TAP INTERFACE TEST - NETWORK PARAMERS SETTING" +
                    System.Environment.NewLine + "The network parameters have not been setted properly. " +
                    System.Environment.NewLine + "This won't stop the installation process but it will preclude " +
                    System.Environment.NewLine + "the correct netproxy working.",true,false);
                netParametersDialog.ShowDialog();
                netParametersDialog.Dispose();
                return -3;
            }
            //netParamForm.Dispose();
            return 0;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Method that tries to set the ip, subnet mask, default gateway
        /// and mac addresses using the .exe file specified as paramerer.
        /// The exec file set also the MTU registry to 1500 and the
        /// AllowNonAdmin registy to 1.
        /// </summary>
        /// <param name="execTestFile">Executable file to change the addresses</param>
        /// <returns>0 if everything went fine, a negative number otherwise</returns>
        private int tryAddressesSetting(string execTestFile)
        {
            int tapTestResult = -4;
            NetworkParametersForm netParamForm = new NetworkParametersForm();

            showNetworkParametersFromDialog(netParamForm);
            DialogResult dr = netParamForm.ShowDialog();

            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                string adapterDescriptor = netParamForm.getAdapterDescriptor();
                string ip      = netParamForm.getIPAddress();
                string mask    = netParamForm.getMaskAddress();
                string gateway = netParamForm.getGatewayAddress();
                string mac     = netParamForm.getMACAddress();
                string ipOptions;
                if (String.IsNullOrEmpty(gateway))
                {
                    ipOptions = "-updateIP -d \"" + adapterDescriptor + "\" -ip " + ip + " -mask " + mask;
                }
                else
                {
                    ipOptions = "-updateIP -d \"" + adapterDescriptor + "\" -ip " + ip + " -mask " + mask + " -gateway " + gateway;
                }
                Process setIPProcess = Process.Start(execTestFile, ipOptions);
                setIPProcess.WaitForExit();
                tapTestResult = setIPProcess.ExitCode;
                if (tapTestResult != 0)
                {
                    TapInterfaceTestResDialog netParametersDialog = new TapInterfaceTestResDialog("TAP INTERFACE TEST - NETWORK PARAMERS SETTING" +
                                                                                                  System.Environment.NewLine + "The ip, netmask and gateway addresses have not been setted properly. " +
                                                                                                  System.Environment.NewLine + "This won't stop the installation process but it will preclude " +
                                                                                                  System.Environment.NewLine + "the correct netproxy working.", true, false);
                    netParametersDialog.ShowDialog();
                    netParametersDialog.Dispose();
                    return(-1);
                }
                string  macOptions    = "-updateMac -d \"" + adapterDescriptor + "\" -a " + mac;
                Process setMacProcess = Process.Start(execTestFile, macOptions);
                setMacProcess.WaitForExit();
                tapTestResult = setMacProcess.ExitCode;
                if (tapTestResult != 0)
                {
                    TapInterfaceTestResDialog netParametersDialog = new TapInterfaceTestResDialog("TAP INTERFACE TEST - NETWORK PARAMERS SETTING" +
                                                                                                  System.Environment.NewLine + "The mac address has not been setted properly. " +
                                                                                                  System.Environment.NewLine + "This won't stop the installation process but it will preclude " +
                                                                                                  System.Environment.NewLine + "the correct netproxy working.", true, false);
                    netParametersDialog.ShowDialog();
                    netParametersDialog.Dispose();
                    return(-2);
                }

                // Run again the test to check the network parameters for the just installed tap interface
                Process tapTestProcess = Process.Start(execTestFile, "-testtap");
                tapTestProcess.WaitForExit();
                tapTestResult = tapTestProcess.ExitCode;
            }
            if ((dr == System.Windows.Forms.DialogResult.Cancel) || (tapTestResult == -4))
            {
                //netParamForm.Dispose();
                TapInterfaceTestResDialog netParametersDialog = new TapInterfaceTestResDialog("TAP INTERFACE TEST - NETWORK PARAMERS SETTING" +
                                                                                              System.Environment.NewLine + "The network parameters have not been setted properly. " +
                                                                                              System.Environment.NewLine + "This won't stop the installation process but it will preclude " +
                                                                                              System.Environment.NewLine + "the correct netproxy working.", true, false);
                netParametersDialog.ShowDialog();
                netParametersDialog.Dispose();
                return(-3);
            }
            //netParamForm.Dispose();
            return(0);
        }