Пример #1
0
        static void Main(string[] args)
        {
            int    seq = 0;
            string url = "rtsp://144.92.136.102";

            RtspClient rtspClient = new RtspClient();
            bool       result     = rtspClient.ConnectServer("144.92.136.102", 554);

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("{0} ", Constants.RTSP_CMD_OPTIONS);
            sb.AppendFormat("{0} RTSP/1.0\r\n", url);
            sb.AppendFormat("CSeq: {0}\r\n", (++seq).ToString());
            sb.AppendFormat("User-Agent: {0}\r\n\r\n", Constants.USER_AGENT_HEADER);

            rtspClient.SendMessage(sb.ToString());
            string response = rtspClient.ReceiveMessage();

            Console.WriteLine(response);

            string[] lines = response.Split(new char[] { '\r', '\n' });
            string   re    = "";
            Dictionary <string, string> p = null;

            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].StartsWith("WWW-Authenticate"))
                {
                    Console.WriteLine(lines[i]);
                    p = ParseDigest(lines[i]);
                    //HA1 = MD5(username: realm:password)
                    //HA2 = MD5(method: digestURI)
                    //response = MD5(HA1: nonce:HA2)
                    var HA1 = MD5("admin:" + p["realm"] + ":1675WisM@d");
                    var HA2 = MD5(Constants.RTSP_CMD_OPTIONS + ":" + url);
                    re = MD5(HA1 + ":" + p["nonce"] + ":" + HA2);
                }
            }


            sb = new StringBuilder();
            sb.AppendFormat("{0} ", Constants.RTSP_CMD_OPTIONS);
            sb.AppendFormat("{0} RTSP/1.0\r\n", url);
            sb.AppendFormat("CSeq: {0}\r\n", (++seq).ToString());
            sb.AppendFormat("Authorization: Digest username=\"{0}\", realm=\"{1}\", nonce=\"{2}\", uri=\"{3}\", response=\"{4}\"\r\n", "admin", p["realm"], p["nonce"], url, re);
            sb.AppendFormat("User-Agent: {0}\r\n\r\n", Constants.USER_AGENT_HEADER);

            rtspClient.SendMessage(sb.ToString());
            response = rtspClient.ReceiveMessage();

            Console.WriteLine(response);
        }