Esempio n. 1
0
 public static void PrintServicePointConnections(ServicePoint sp, HttpResponse resp)
 {
     Type type = sp.GetType();
     BindingFlags bindingFlag = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
     FieldInfo field = type.GetField("m_ConnectionGroupList", bindingFlag);
     Hashtable value = (Hashtable)field.GetValue(sp);
     List<object> list = value.Keys.Cast<object>().ToList<object>();
     int count = 0;
     resp.Write(string.Format("<BR/><BR/>ServicePoint: {0} (Connection Limit: {1}, Reported connections: {2})", sp.Address, sp.ConnectionLimit, sp.CurrentConnections));
     foreach (object obj in list)
     {
         object item = value[obj];
         FieldInfo fieldInfo = item.GetType().GetField("m_ConnectionList", bindingFlag);
         ArrayList arrayLists = (ArrayList)fieldInfo.GetValue(item);
         resp.Write(string.Format("{0}", obj));
         count += arrayLists.Count;
     }
     resp.Write(string.Format("<BR/><BR/>ConnectionGroupCount: {0}, Total Connections: {1}", list.Count, count));
 }
Esempio n. 2
0
        //private void Log(string fmt, params object[] args)
        //{
        //    connections.Add(string.Format(fmt, args));
        //}

        private ServicePointData GetServicePointConnections(ServicePoint sp)
        {
            var spType = sp.GetType();
            var privateOrPublicInstanceField = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
            var connectionGroupField         = spType.GetField("m_ConnectionGroupList", privateOrPublicInstanceField);
            var value            = (Hashtable)connectionGroupField.GetValue(sp);
            var connectionGroups = value.Keys.Cast <object>().ToList();
            var totalConnections = 0;

            var spd = new ServicePointData
            {
                Address            = sp.Address,
                ConnectionLimit    = sp.ConnectionLimit,
                CurrentConnections = sp.CurrentConnections
            };

            //Log("ServicePoint: {0} (Connection Limit: {1}, Reported connections: {2})", sp.Address, sp.ConnectionLimit, sp.CurrentConnections);

            foreach (var key in connectionGroups)
            {
                var connectionGroup = value[key];
                var groupType       = connectionGroup.GetType();
                var listField       = groupType.GetField("m_ConnectionList", privateOrPublicInstanceField);
                var listValue       = (ArrayList)listField.GetValue(connectionGroup);

                //Console.WriteLine("{3} {0}\nConnectionGroup: {1} Count: {2}",sp.Address, key,listValue.Count, DateTime.Now);
                //Log("{0}", key);

                spd.ConnectionGroups.Add(key);

                totalConnections += listValue.Count;
            }

            //Log("ConnectionGroupCount: {0}, Total Connections: {1}", connectionGroups.Count, totalConnections);
            spd.ConnectionGroupCount = connectionGroups.Count;
            spd.TotalConnections     = totalConnections;

            return(spd);
        }
        private ServicePointStatusServicePoint PrintServicePointConnections(ServicePoint sp)
        {
            var spType = sp.GetType();
            var privateOrPublicInstanceField = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
            var connectionGroupField         = spType.GetField("m_ConnectionGroupList", privateOrPublicInstanceField);
            var value            = (Hashtable)connectionGroupField.GetValue(sp);
            var connectionGroups = value.Keys.Cast <object>().ToList();

            var servicePointStatus = new ServicePointStatusServicePoint
            {
                Address              = sp.Address,
                ConnectionLimit      = sp.ConnectionLimit,
                CurrentConnection    = sp.CurrentConnections,
                ConnectionGroupCount = connectionGroups.Count,
                TotalConnections     = 0
            };

            foreach (var key in connectionGroups)
            {
                var connectionGroup = value[key];
                var groupType       = connectionGroup.GetType();
                var listField       = groupType.GetField("m_ConnectionList", privateOrPublicInstanceField);
                var listValue       = (ArrayList)listField.GetValue(connectionGroup);
                //Console.WriteLine("{3} {0}\nConnectionGroup: {1} Count: {2}",sp.Address, key,listValue.Count, DateTime.Now);

                servicePointStatus.ConnectionGroups.Add(new ServicePointStatusConnectionGroup
                {
                    Key   = key,
                    Count = listValue.Count
                });

                servicePointStatus.TotalConnections += listValue.Count;
            }

            return(servicePointStatus);
        }
Esempio n. 4
0
        public unsafe SendResponse SendIbet(string requestUri, string method, string userAgent, CookieContainer cookieContainer,
                                            byte[] data, string host, string accept, string referer = "", string contentType = "")
        {
            //ServicePointManager.ServerCertificateValidationCallback =
            //    delegate
            //    {
            //        return true;
            //    };

            HttpWebRequest  request;
            HttpWebResponse response     = null;
            SendResponse    sendResponse = new SendResponse();

            try
            {
                request = WebRequest.Create(requestUri) as HttpWebRequest;

                request.ServicePoint.BindIPEndPointDelegate = delegate(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount)
                {
                    if (remoteEndPoint.AddressFamily != System.Net.Sockets.AddressFamily.InterNetworkV6)
                    {
                        if (string.IsNullOrEmpty(RealIpAddress))
                        {
                            return(new IPEndPoint(IPAddress.Any, 0));
                        }
                        else
                        {
                            return(new IPEndPoint(IPAddress.Parse(RealIpAddress), 0));
                        }
                    }
                    else
                    {
                        return(new IPEndPoint(IPAddress.IPv6Any, 0));
                    }
                };

                request.Method    = method;
                request.UserAgent = userAgent;
                request.Host      = host;
                request.Proxy     = null;
                request.UnsafeAuthenticatedConnectionSharing = true;
                request.Accept          = accept;
                request.ProtocolVersion = HttpVersion.Version11;
                request.Timeout         = 10000;
                request.CookieContainer = cookieContainer;

                request.AllowAutoRedirect = false;
                request.ServicePoint.Expect100Continue = false;

                request.Headers.Add("Accept-Language", "en-US,en;q=0.5");
                request.Headers.Add("X-Requested-With", "XMLHttpRequest");

                if (!string.IsNullOrEmpty(contentType))
                {
                    request.ContentType = contentType;
                }

                if (!string.IsNullOrEmpty(referer))
                {
                    request.Referer = referer;
                }

                if (string.IsNullOrEmpty(IpFake))
                {
                    request.KeepAlive = true;
                    request.Headers.Add("Accept-Encoding", "gzip, deflate");
                    ServicePoint servicePoaint = request.ServicePoint;
                    PropertyInfo property      = servicePoaint.GetType().GetProperty("HttpBehaviour", BindingFlags.Instance | BindingFlags.NonPublic);
                    property.SetValue(servicePoaint, (byte)0, null);
                }
                else
                {
                    request.Headers.Add("X-Forwarded-For", IpFake);
                    request.Headers.Add("Accept-Encoding", "gzip, deflate,sdch");
                }

                request.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);

                if (data != null)
                {
                    // Set the content length in the request headers
                    request.ContentLength = data.Length;
                    // Write data
                    using (Stream stream = request.GetRequestStream())
                    {
                        stream.Write(data, 0, data.Length);
                    }
                }

                // Get response
                response = request.GetResponse() as HttpWebResponse;

                if (request.HaveResponse == true && response != null)
                {
                    // Get the response stream
                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        sendResponse.StatusCode        = response.StatusCode;
                        sendResponse.StatusDescription = response.StatusDescription;
                        sendResponse.Result            = reader.ReadToEnd();
                    }
                }
            }
            catch (WebException wex)
            {
                if (wex.Response != null)
                {
                    using (HttpWebResponse errorResponse = (HttpWebResponse)wex.Response)
                    {
                        sendResponse.StatusCode        = errorResponse.StatusCode;
                        sendResponse.StatusDescription = errorResponse.StatusDescription;
                    }
                }
            }
            catch (Exception ex)
            {
                sendResponse.StatusCode = HttpStatusCode.NotFound;
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }
            }

            return(sendResponse);
        }
Esempio n. 5
0
        public static SendResponse SendIsn(string requestUri, string method, string userAgent, CookieContainer cookieContainer,
                                           byte[] data, string host, string accept, string referer = "", string contentType = "", string origin = "")
        {
            HttpWebRequest  request;
            HttpWebResponse response     = null;
            SendResponse    sendResponse = new SendResponse();

            try
            {
                request = WebRequest.Create(requestUri) as HttpWebRequest;



                request.Method    = method;
                request.UserAgent = userAgent;
                request.Host      = host;
                // request.Proxy = null;
                //       request.UnsafeAuthenticatedConnectionSharing = true;
                request.Accept          = accept;
                request.ProtocolVersion = HttpVersion.Version11;
                request.KeepAlive       = true;
                request.Timeout         = 10000;
                request.CookieContainer = cookieContainer;

                // request.AllowAutoRedirect = false;
                //         request.ServicePoint.Expect100Continue = false;

                request.Headers.Add("Accept-Language", "en-US,en;q=0.8");
                request.Headers.Add("Accept-Encoding", "gzip, deflate");
                request.Headers.Add("X-Requested-With", "XMLHttpRequest");

                //force keep alive
                ServicePoint servicePoaint = request.ServicePoint;
                PropertyInfo property      = servicePoaint.GetType().GetProperty("HttpBehaviour", BindingFlags.Instance | BindingFlags.NonPublic);
                property.SetValue(servicePoaint, (byte)0, null);

                if (!string.IsNullOrEmpty(contentType))
                {
                    request.ContentType = contentType;
                }

                if (!string.IsNullOrEmpty(referer))
                {
                    request.Referer = referer;
                }

                if (!String.IsNullOrEmpty(origin))
                {
                    request.Headers.Add("Origin", origin);
                }

                request.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);

                if (data != null)
                {
                    // Set the content length in the request headers
                    request.ContentLength = data.Length;
                    // Write data
                    using (Stream stream = request.GetRequestStream())
                    {
                        stream.Write(data, 0, data.Length);
                    }
                }

                // Get response
                response = request.GetResponse() as HttpWebResponse;

                if (request.HaveResponse == true && response != null)
                {
                    // Get the response stream
                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        sendResponse.StatusCode        = response.StatusCode;
                        sendResponse.StatusDescription = response.StatusDescription;
                        sendResponse.SetCookie         = response.Headers.Get("Set-Cookie");
                        sendResponse.Result            = reader.ReadToEnd();
                    }
                }
            }
            catch (WebException wex)
            {
                if (wex.Response != null)
                {
                    using (HttpWebResponse errorResponse = (HttpWebResponse)wex.Response)
                    {
                        sendResponse.StatusCode        = errorResponse.StatusCode;
                        sendResponse.StatusDescription = errorResponse.StatusDescription;
                    }
                }
            }
            catch (Exception ex)
            {
                sendResponse.StatusCode = HttpStatusCode.NotFound;
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }
            }

            return(sendResponse);
        }