Ejemplo n.º 1
0
        //Dialup
        private Error CreaVPNxTel()
        {
            Error cxnErr = new Error();

            string telDefault = TransacManager.ProtoConfig.CONFIG.Telefono;// "08006665807";
            string prefijo = TransacManager.ProtoConfig.CONFIG.CxnTelPrefijo;// "11000";
            string separador = "w";
            if (String.IsNullOrEmpty(prefijo))
            {
                prefijo = "";
                separador = "";
            }
            string modemDefault = TransacManager.ProtoConfig.CONFIG.CxnTelNombreModem;// "Conexant USB CX93010 ACF Modem";
            string user = TransacManager.ProtoConfig.CONFIG.CxnTelUser;// "bmtp";
            string pass = TransacManager.ProtoConfig.CONFIG.CxnTelPass;// "bmtp";
            uint timeout = TransacManager.ProtoConfig.CONFIG.CxnTelTimeout;

            string nombre1, nombre2, nombre3, port1, port2, port3, tel1, tel2, tel3;

            Conexion cxn = new Conexion();

                string rdo = cxn.Leer_XMLprn(out nombre1, out nombre2, out nombre3, out port1, out  port2, out port3, out tel1, out tel2, out tel3, TransacManager.ProtoConfig.CONFIG);
                string[] tel = new string[4];

                if (rdo == null)
                {
                    tel[0] = tel1;
                    tel[1] = tel2;
                    tel[2] = tel3;
                    tel[3] = telDefault;
                }
                else
                    tel[0] = telDefault;

                string path = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User);

                using (RasPhoneBook pbk = new RasPhoneBook())
                {
                    pbk.Open(path);

                    // Find the device that will be used to dial the connection.
                    RasDevice device = RasDevice.GetDevices().Where(u => u.Name == modemDefault && u.DeviceType == RasDeviceType.Modem).First();

                    RasEntry entry;

                    ICollection<RasConnection> conecciones = RasConnection.GetActiveConnections();

                    if (conecciones.Count > 0)
                    {
                        RasConnection conn1 = conecciones.Where(o => o.EntryName == "BMTP Dial up").First();
                        conn1.HangUp();
                    }

                    pbk.Entries.Clear();

                    try
                    {
                        entry = RasEntry.CreateDialUpEntry("BMTP Dial up", prefijo + separador + tel[0], device);

                        if (rdo == null)
                        {
                            entry.AlternatePhoneNumbers.Add(prefijo + separador + tel[1]);
                            entry.AlternatePhoneNumbers.Add(prefijo + separador + tel[2]);
                            entry.AlternatePhoneNumbers.Add(prefijo + separador + telDefault);
                            LogBMTP.LogMessage("Se leyó PRN. Telefonos alternativos cargados.", lvlLogCxn, TimeStampLog);
                        }
                        else
                        {
                            LogBMTP.LogMessage("No hay PRN. Intentará conectar con número telefónico por defecto.", lvlLogCxn, TimeStampLog);
                        }

                        //entry.Options.ModemLights = true;
                        //entry.Options.ShowDialingProgress = true;
                        //entry.Options.TerminalBeforeDial = true;
                        //entry.Options.TerminalAfterDial = true;

                        pbk.Entries.Add(entry);

                        using (RasDialer dialer = new RasDialer())
                        {
                            dialer.Dispose();
                            dialer.EntryName = "BMTP Dial up";
                            dialer.PhoneBookPath = path;
                            dialer.Credentials = new NetworkCredential(user, pass);

                            dialer.Timeout = (int)timeout;
                            dialer.Options.DisableReconnect = false;
                            dialer.Options.SetModemSpeaker = true;

                            dialer.Dial();
                        }
                    }
                    catch (Exception e)
                    {
                        pbk.Entries.Clear();
                        LogBMTP.LogMessage(e.ToString(), lvlLogExcepciones, TimeStampLog);

                        cxnErr.CodError = (int)ErrComunicacion.CXN_TELEFONOex;
                        cxnErr.Descripcion = "Error de conexión. No puede establecerse una comunicación por telefono.";
                        cxnErr.Estado = 0;
                        LogBMTP.LogMessage("Excepción: " + cxnErr.CodError + " " + cxnErr.Descripcion, lvlLogExcepciones, TimeStampLog);
                        LogBMTP.LogMessage("Excepción: " + e.ToString(), lvlLogExcepciones, TimeStampLog);
                    }
                }

                return cxnErr;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 宽带ip转换
        /// </summary>
        /// <param name="kdlj">宽带连接名称 如:本地连接,宽带连接</param>
        /// <param name="userName">帐号</param>
        /// <param name="pwd">密码</param>
        public void ChangeIp(string kdlj, string userName, string pwd)
        {
            //hx.Mset.IsChangeIp = hx.Mset.IsChangeIp;
            LogServer.WriteLog("开始准备更换IP", "changeIp");

            HANDUPCON:
            string oldIpAddress;
            RasConnection oldConn;
            GetIpAddress(out oldIpAddress, out oldConn);
            string entryName = "";
            if (oldConn != null)
            {

                try
                {
                    entryName = oldConn.EntryName;
                    RasIPInfo ipAddresses = (RasIPInfo) oldConn.GetProjectionInfo(RasProjectionType.IP);
                    string oldIp = ipAddresses.IPAddress.ToString();
                    LogServer.WriteLog("现在名称:" + entryName + "IP是" + oldIp, "changeIp");
                    LogServer.WriteLog("开始挂断", "changeIp");
                    oldConn.HangUp(10*1000);
                    //Thread.Sleep(hx.Mset.RasHangUpSleepTime);
                    if (RasConnection.GetActiveConnectionById(oldConn.EntryId) != null)
                    {
                        LogServer.WriteLog("结束挂断失败,重新挂断", "changeIp");
                        goto HANDUPCON;
                    }
                    oldConn = null;
                    LogServer.WriteLog("结束挂断", "changeIp");
                }
                catch (Exception ex)
                {
                    LogServer.WriteLog("宽带连接挂断失败," + ex.Message, "changeIp");
                }
            }
            int error = 0;
            do
            {
                try
                {
                    //  var dt = SqliteHelper.GetDataTable("select * from sys_config");
                    RasDialer rs = new RasDialer();
                    if (entryName == "")
                    {
                        entryName = kdlj; // dt.Rows[0]["SC_NetEntryName"].ToString();
                    }
                    rs.EntryName = entryName;
                    rs.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers);
                    rs.Credentials = new NetworkCredential(userName, pwd);
                    rs.Dial();
                    rs.Dispose();
                    LogServer.WriteLog("开始重新拨号", "changeIp");
                    break;
                }
                catch (Exception ex)
                {
                    error++;
                    LogServer.WriteLog("宽带重新拨号失败" + ex.Message, "changeIp");
                    Thread.Sleep(30000);
                }
            } while (error < 5);
            if (error >= 5)
            {
                LogServer.WriteLog("宽带重新拨号5次数失败", "changeIp");
                return;
            }

            if (oldConn != null)
            {
                string ipAddresses;
                GetIpAddress(out ipAddresses, out oldConn);
                if (oldIpAddress == ipAddresses)
                {
                    //addlog("IP和上次重复,重新拨号");
                    LogServer.WriteLog("IP和上次重复,重新拨号", "changeIp");
                    Thread.Sleep(DialFaildSleepTime);
                    goto HANDUPCON;
                }
                else
                {
                    if (historyIps.Contains(ipAddresses))
                    {
                        LogServer.WriteLog("IP和前" + IPLoopCount + "次重复,重新拨号", "changeIp");
                        Thread.Sleep(DialFaildSleepTime);
                        goto HANDUPCON;
                    }
                    if (historyIps.Count >= IPLoopCount)
                    {
                        historyIps.RemoveAt(0);
                        historyIps.Add(ipAddresses);
                    }
                    historyIps.Add(ipAddresses);
                }

                //addlog("现在的IP是" + ipAddresses);

            }
            //main.pppoeact = true;
            LogServer.WriteLog("更换成功", "changeIp");
            //addlog("更换成功.. ");
        }
 public static void Disconnect()
 {
     try
     {
         if (ms_rasdialer != null)
         {
             ms_rasdialer.Dispose();                    
         }
         ms_rasdialer = new RasDialer();
         ReadOnlyCollection<RasConnection> connections = ms_rasdialer.GetActiveConnections();
         if (connections != null && connections.Count > 0)
         {
             foreach (RasConnection connection in connections)
             {
                 if (ms_entryname == connection.EntryName)
                 {
                     connection.HangUp();
                 }
             }
         }
         ms_rasdialer.Dispose();
     }
     catch (RasException re)
     {
         log.Error("ADSLManger: Disconnect", re);
     }
 }