我现在有两个文件a.aspx,b.aspx 我想扫描里面的某个字符串比如病毒.怎么才知道哪个文件包含这个字符串 呢

解决方案 »

  1.   

    StreamReader my_stream_reader = new StreamReader(@"E:\test.txt");
    string getligne = my_stream_reader.ReadToEnd().ToString();string svi = "xxx";
    if(getligne.Contains(svi))
    //..
      

  2.   

    人家读取的是a.aspx里的,不是text啊
      

  3.   

    string s=File.ReadAllText("");
    在添加数据时判断关键词
      

  4.   

    楼上正解,就把aspx当文本文件读一遍不就行了?
      

  5.   

    是的,如果能够读取aspx的话,和txt一样的;如果是客户端读取网页的形式,那是用webclient或者xxx吧
      

  6.   

    string[] pipei = txt_file.Text.Replace("\r","").Split('\n');
                string url = "http://www.baidu.com";
                System.IO.Stream stream = null;
                WebClient client = new WebClient();
                stream = client.OpenRead(url);
                //查找选择目录下所有文件列表
                Response.Write("此目录下文件列表为:" + "<br/>");
                DirectoryInfo di = new DirectoryInfo(Server.MapPath(TextBox2.Text));
                FileSystemInfo[] fsi = di.GetFileSystemInfos();
                List<string> ContentInfo=new List<string>();
                for (int i = 0; i < fsi.Length; i++)
                {
                    if (fsi[i].Name.Contains(".aspx") || fsi[i].Name.Contains(".txt") || fsi[i].Name.Contains(".htm") || fsi[i].Name.Contains(".aspx.cs"))
                    {
                        StreamReader sr = new StreamReader((Server.MapPath(TextBox2.Text)) + "\\" + fsi[i].Name.Trim(), System.Text.Encoding.GetEncoding("gb2312"));
                        ContentInfo.Add(sr.ReadToEnd());
                        sr.Close();
                        Response.Write(fsi[i].Name + "<br/>");//用来输出目录下面的文件列表
                    }
                   
                }
                  //s查找特征码文件;
                string[] ReKey = txt_file.Text.Replace("\r","").Split('\n');
                List<string> DirCat = new List<string>();
                int m_count = 0;
                foreach (string checkitem in ContentInfo)
                {
                    for (int i = 0; i < ReKey.Length; i++)
                    {
                        if (checkitem.Contains(ReKey[i]))
                        {
                            DirCat.Add(ReKey[i]);
                            m_count = m_count + 1;
                        }
                    }
                }
                //记录哪个文件包含扫描出来的特征码
               
                //这些代码如何写呢?把代码贴上来,我刚学.NET,能不能说的详细点各位 ...谢了
      

  7.   

     string[] ReKey = txt_file.Text.Replace("\r","").Split('\n');
                List<string> DirCat = new List<string>();
                int m_count = 0;
                foreach (string checkitem in ContentInfo)
                {
                    for (int i = 0; i < ReKey.Length; i++)
                    {
                        if (checkitem.Contains(ReKey[i]))
                        {
                            DirCat.Add(ReKey[i]);
                            m_count = m_count + 1;
                        }
                    }
                }我是这样获取目录文件内容的,能知道特征码在哪个文件吗?
      

  8.   

    原理就是拿到a.aspx文件的内容,当然这个要分清楚你要拿的是生成HTML的网页内容,还是这个文件的代码。然后就拿来indexof查找你要查询的字符串就可以了。
      

  9.   

    其實幾行代碼就搞定了System.IO.FileStream fs = new System.IO.FileStream("完整文件名", System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.StreamReader sr = new System.IO.StreamReader(fs);
            string s = sr.ReadToEnd();
            s.IndexOf("你要找的內容");
            sr.Close();
            fs.Close();
      

  10.   


    public class FileInfo
    {
    public string strFileName;
    public string strFileContent;
    }string[] pipei = txt_file.Text.Replace("\r","").Split('\n'); string url = "http://www.baidu.com"; System.IO.Stream stream = null; WebClient client = new WebClient(); stream = client.OpenRead(url); //查找选择目录下所有文件列表  Response.Write("此目录下文件列表为:" + "<br/>"); DirectoryInfo di = new DirectoryInfo(Server.MapPath(TextBox2.Text)); FileSystemInfo[] fsi = di.GetFileSystemInfos(); List<FileInfo> ContentInfo=new List<FileInfo>(); for (int i = 0; i < fsi.Length; i++) { if (fsi[i].Name.Contains(".aspx") || fsi[i].Name.Contains(".txt") || fsi[i].Name.Contains(".htm") || fsi[i].Name.Contains(".aspx.cs")) { StreamReader sr = new StreamReader((Server.MapPath(TextBox2.Text)) + "\\" + fsi[i].Name.Trim(), System.Text.Encoding.GetEncoding("gb2312")); 
    FileInfo fi=new FileInfo();
    fi.strFileName=(Server.MapPath(TextBox2.Text)) + "\\" + fsi[i].Name.Trim();
    fi.strFileContent=sr.ReadToEnd().ToString();
    ContentInfo.Add(fi); sr.Close(); Response.Write(fsi[i].Name + "<br/>");//用来输出目录下面的文件列表  } } //s查找特征码文件;  string[] ReKey = txt_file.Text.Replace("\r","").Split('\n'); List<string> DirCat = new List<string>();List<string> hasKeyFileName=new List<string>(); int m_count = 0; foreach (FileInfo checkitem in ContentInfo) { for (int i = 0; i < ReKey.Length; i++) { if (checkitem.strFileContent.Contains(ReKey[i])) { DirCat.Add(ReKey[i]); m_count = m_count + 1; hasKeyFileName.Add(checkitem.strFileName);} } } //记录哪个文件包含扫描出来的特征码 //这些代码如何写呢?
    //hasKeyFileName 中的值即为包含key的文件名
      

  11.   

    本帖最后由 amandag 于 2010-09-01 18:40:45 编辑
      

  12.   

    这个要看你想看这两个页面什么时候包含的字符串了。
    因为ASPX文件在运行之后,可能读取了服务器上的其他地方的信息,
    本身没有“病毒”,可能读取之后就有了“病毒”了。
    如果只是想看文件本身,上面说的把它当一个普通的文本文件,加载之后判断就可以
    如果想看运行状态下的文件里面的内容,那要先获取到这个文本中的字符串,在进行判断
      

  13.   


        /// <summary>
        /// 检查字符串str中有没有指定字符a 当然a只是个代表
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static void Show(string str)
        {
            if (str.Contains("a"))
            {
                //字符串str含有 a 字母
            }
            else
            {
                //字符串str不含 a 字母
            }
        }