Пример #1
0
        public bool MatchSslCertName(IEnumerable <string> certNames)
        {
            IPHostEntry hostEntry = Dns.GetHostEntry(this.Host);

            using (IEnumerator <string> enumerator = certNames.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    string current = enumerator.get_Current();
                    if (current.StartsWith("::ffff:"))
                    {
                        string      text        = current.Substring("::ffff:".get_Length());
                        IPHostEntry hostEntry2  = Dns.GetHostEntry(text);
                        IPAddress[] addressList = hostEntry2.get_AddressList();
                        for (int i = 0; i < addressList.Length; i++)
                        {
                            IPAddress   iPAddress    = addressList[i];
                            IPAddress[] addressList2 = hostEntry.get_AddressList();
                            for (int j = 0; j < addressList2.Length; j++)
                            {
                                IPAddress iPAddress2 = addressList2[j];
                                if (iPAddress2.Equals(iPAddress))
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }
            string text2 = string.Format("TcpConnection - MatchSslCertName failed.", new object[0]);

            using (IEnumerator <string> enumerator2 = certNames.GetEnumerator())
            {
                while (enumerator2.MoveNext())
                {
                    string current2 = enumerator2.get_Current();
                    text2 += string.Format("\n\t certName: {0}", current2);
                }
            }
            IPAddress[] addressList3 = hostEntry.get_AddressList();
            for (int k = 0; k < addressList3.Length; k++)
            {
                IPAddress iPAddress3 = addressList3[k];
                text2 += string.Format("\n\t hostAddress: {0}", iPAddress3);
            }
            this.LogWarning.Invoke(text2);
            return(false);
        }
Пример #2
0
        private void GetHostEntryCallback(IAsyncResult ar)
        {
            IPHostEntry iPHostEntry = Dns.EndGetHostByName(ar);

            Array.Sort <IPAddress>(iPHostEntry.get_AddressList(), delegate(IPAddress x, IPAddress y)
            {
                if (x.get_AddressFamily() < y.get_AddressFamily())
                {
                    return(-1);
                }
                if (x.get_AddressFamily() > y.get_AddressFamily())
                {
                    return(1);
                }
                return(0);
            });
            IPAddress[] addressList = iPHostEntry.get_AddressList();
            for (int i = 0; i < addressList.Length; i++)
            {
                IPAddress iPAddress = addressList[i];
                this.m_candidateIPAddresses.Enqueue(iPAddress);
            }
            this.ConnectInternal();
        }
Пример #3
0
 public static bool GetHostAddressByDns(string hostName, out string address)
 {
     address = string.Empty;
     try
     {
         IPHostEntry hostEntry   = Dns.GetHostEntry(hostName);
         IPAddress[] addressList = hostEntry.get_AddressList();
         int         num         = 0;
         if (num < addressList.Length)
         {
             IPAddress iPAddress = addressList[num];
             address = iPAddress.ToString();
             return(true);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(false);
 }
Пример #4
0
 public void AsyncGetHostEntry(string host, Action <IPHostEntry> resultAction)
 {
     Logger.DEBUG(host);
     try
     {
         IPAddress iPAddress = null;
         if (IPAddress.TryParse(host, ref iPAddress))
         {
             IPHostEntry iPHostEntry = new IPHostEntry();
             iPHostEntry.set_AddressList(new IPAddress[]
             {
                 iPAddress
             });
             resultAction.Invoke(iPHostEntry);
         }
         else if (this.dnsCache.ContainsKey(host))
         {
             IPHostEntry iPHostEntry2 = this.dnsCache.get_Item(host);
             resultAction.Invoke(iPHostEntry2);
         }
         else
         {
             Action <IAsyncResult> action = delegate(IAsyncResult ar)
             {
                 try
                 {
                     string text = (string)ar.get_AsyncState();
                     Logger.DEBUG(text + " end");
                     IPHostEntry entry = Dns.EndGetHostEntry(ar);
                     Logger.DEBUG(text + " end, entry.AddressList.Length=" + entry.get_AddressList().Length.ToString());
                     Action <int, Dictionary <string, object> > action2 = delegate(int status, Dictionary <string, object> content)
                     {
                         string               text2        = content.get_Item("host") as string;
                         IPHostEntry          iPHostEntry3 = content.get_Item("entry") as IPHostEntry;
                         Action <IPHostEntry> action3      = content.get_Item("resultAction") as Action <IPHostEntry>;
                         this.dnsCache.set_Item(text2, entry);
                         action3.Invoke(entry);
                     };
                     Message message = new Message();
                     message.status = 0;
                     message.content.set_Item("host", text);
                     message.content.set_Item("entry", entry);
                     message.content.set_Item("resultAction", resultAction);
                     message.action = action2;
                     this.EnqueueDrive(message);
                 }
                 catch (Exception ex2)
                 {
                     Logger.ERROR(ex2.get_Message() + ":" + ex2.get_StackTrace());
                 }
             };
             Logger.DEBUG(host + " begin");
             Dns.BeginGetHostEntry(host, new AsyncCallback(action.Invoke), host);
         }
     }
     catch (Exception ex)
     {
         resultAction.Invoke(null);
         Logger.ERROR(ex.get_Message() + ":" + ex.get_StackTrace());
     }
 }
Пример #5
0
        public void BeginGetGameZoneUrl(Dictionary <string, string> userDataDict, Action <Dictionary <string, string> > action)
        {
            this.userData        = userDataDict;
            this.callbackForGame = action;
            string           text = "wzry.broker.tplay.qq.com";
            int              num  = 5692;
            List <IPAddress> list = new List <IPAddress>();

            if (text.get_Length() > 0)
            {
                try
                {
                    IPAddress iPAddress = null;
                    if (IPAddress.TryParse(text, ref iPAddress))
                    {
                        list.Add(iPAddress);
                    }
                    else
                    {
                        IPHostEntry hostEntry   = Dns.GetHostEntry(text);
                        IPAddress[] addressList = hostEntry.get_AddressList();
                        for (int i = 0; i < addressList.Length; i++)
                        {
                            IPAddress iPAddress2 = addressList[i];
                            list.Add(iPAddress2);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.Log(ex.get_Message());
                    this.NotifyShowZone(false);
                }
            }
            if (list.get_Count() > 0)
            {
                int        num2       = new Random().Next(list.get_Count());
                IPEndPoint iPEndPoint = new IPEndPoint(list.get_Item(num2), num);
                Socket     socket     = new Socket(2, 1, 6);
                socket.SetSocketOption(65535, 4101, this.sendRcvTimeOut);
                socket.SetSocketOption(65535, 4102, this.sendRcvTimeOut);
                Debug.Log("Begin Connet");
                IAsyncResult asyncResult     = socket.BeginConnect(iPEndPoint, null, null);
                WaitHandle   asyncWaitHandle = asyncResult.get_AsyncWaitHandle();
                try
                {
                    if (!asyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds((double)this.connectTimeOut)))
                    {
                        Debug.Log("Connect Time Out:" + this.connectTimeOut.ToString());
                        this.CloseSocket(socket);
                    }
                    else
                    {
                        try
                        {
                            socket.EndConnect(asyncResult);
                            if (asyncResult.get_IsCompleted())
                            {
                                string actReqJson = this.GetActReqJson();
                                this.AsynCallBroker(socket, actReqJson);
                            }
                        }
                        catch (Exception ex2)
                        {
                            Debug.Log(ex2.get_Message());
                            this.CloseSocket(socket);
                        }
                    }
                }
                catch (Exception ex3)
                {
                    Debug.Log(ex3.get_Message());
                    this.CloseSocket(socket);
                }
                finally
                {
                    asyncWaitHandle.Close();
                }
            }
        }