c# winform 火狐浏览器 查看cookie
c# winform 火狐浏览器 查看cookie
Firefox的Cookie数据位于:%APPDATA%\Mozilla\Firefox\Profiles\ 目录中的xxx.default目录,名为cookies.sqlite的文件。
如:C:\Users\jay\AppData\Roaming\Mozilla\Firefox\Profiles\ji4grfex.default\cookies.sqlite
在Firefox中查看cookie, 可以选择”工具 > 选项 >” “隐私 > 显示cookie”。
1、先获取cookies.sqlite文件路径
2、SQLite数据库需要引用System.Data.SQLite
下载地址:http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
得到System.Data.SQLite.dll添加到工程引用;
*可以使用SQLite Database Browser来查看数据:
下载地址:http://sourceforge.net/projects/sqlitebrowser/
3、SQLite.Interop.dll文件要复制到输出目录中
4、通过name和host字段查询返回value值,value带有中文要转译
HttpUtility.UrlDecode需要引用System.Web
好吧,SQLite确实也很强大,只不过在这里并不是很爽,原因是需要以上2个dll文件才可以正常使用。
那下面就用另一种办法实现下,虽然效率没有上面的高,但已足够用了。
首先使用记事本打开cookies.sqlite文件观察
得到格式:
站点(域名)+Cookie名称+内容+域+路径
实现通过指定名称+域,取中间的部分就是cookie值。
使用正则表达式:
(?<=jd.com_pst)(?'value'[\w%]+)(?=.jd.com)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SQLite;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms; namespace FirefoxCookie
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private string dbPath = string.Empty; //cookies.sqlite文件路径 private void Form1_Load(object sender, EventArgs e)
{
DirectoryInfo di = new DirectoryInfo(System.Environment.GetEnvironmentVariable("AppData") + @"\Mozilla\Firefox\Profiles\");
DirectoryInfo[] dirs = di.GetDirectories();//获取子文件夹列表
if (dirs != null)
{
dbPath = dirs[].FullName + "\\cookies.sqlite";
} //所有cookie
this.dataGridView1.DataSource = GetTable("select * from moz_cookies"); //所有站点
this.comboBox1.DataSource = GetTable("select Distinct baseDomain from moz_cookies");
this.comboBox1.DisplayMember = "baseDomain"; //注册事件 属性值更改时触发
comboBox1.SelectedIndexChanged += new System.EventHandler(this.SelectedIndexChanged); } //通过指定站点查找
private void SelectedIndexChanged(object sender, EventArgs e)
{
string txt = ((ComboBox)sender).Text;
this.dataGridView1.DataSource = GetTable("select * from moz_cookies where baseDomain=@baseDomain", new SQLiteParameter("baseDomain", txt));
} private void button1_Click(object sender, EventArgs e)
{
string name = this.txtName.Text.Trim();
string host = this.txtHost.Text.Trim();
string value = string.Empty;
if (File.Exists(dbPath))
{
string sqlStr = "select value from moz_cookies where name=@name and host=@host";
SQLiteParameter[] pms = new SQLiteParameter[]{
new SQLiteParameter("name", name),
new SQLiteParameter("host", host)
};
value = (string)ExecuteScalar(sqlStr, pms) ?? "未找到!";
}
value = System.Web.HttpUtility.UrlDecode(value); //中文需要转码
this.txtValue.Text = value;
} private object ExecuteScalar(string sql, params SQLiteParameter[] pms)
{ using (SQLiteConnection conn = new SQLiteConnection("Data Source =" + dbPath))
{
using (SQLiteCommand com = new SQLiteCommand(sql, conn))
{
if (pms != null)
{
com.Parameters.AddRange(pms);
}
conn.Open();
return com.ExecuteScalar();
}
}
} private DataTable GetTable(string sql, params SQLiteParameter[] pms)
{
using (SQLiteConnection conn = new SQLiteConnection("Data Source =" + dbPath))
{
using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(sql, conn))
{
DataTable dt = new DataTable();
if (pms != null)
{
adapter.SelectCommand.Parameters.AddRange(pms);
}
conn.Open();
adapter.Fill(dt);
return dt;
}
}
} private void button2_Click(object sender, EventArgs e)
{
string str = string.Empty;
using (FileStream fs = new FileStream(dbPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default))
{
str = sr.ReadToEnd();
}
} string pattern = string.Format(@"(?<={0})(?'value'[\w%]+)(?={1})", this.txtName.Text.Trim(), this.txtHost.Text.Trim());
Match match = Regex.Match(str, pattern);
if (match.Success)
{
string value = match.Groups["value"].Value;
value = System.Web.HttpUtility.UrlDecode(value); //中文需要转码
this.txtValue.Text = value;
}
}
}
}
下载地址:
http://download.csdn.net/detail/h_gxi/9059561
c# winform 火狐浏览器 查看cookie的更多相关文章
- 浏览器查看cookie
今天总结下,教你怎样查看一些浏览器的Cookie,比如IE.Firefox.Chrome的Cookies等.下面分块介绍,以后会关注一些没有讲到的浏览器获取Cookie的方法. 1.Firefox浏览 ...
- 怎么清除火狐浏览器的cookie?
火狐浏览器清除Cookie方法/步骤 1.打开火狐浏览器.并在火狐浏览器工具栏找到并单击“工具”下的“选项”. 2.在打开的“火狐浏览器选项”程序窗口中,找到工具栏中的“隐私”并单击,在隐私选项下找到 ...
- 关于火狐浏览器设置cookie的一个问题
最近发现我一个项目的网页,里面的cookie无法添加了,急的我瞪着我的PHP代码沉思了好久,我默认用的火狐浏览器,然而我默默的打开另一个叫360的浏览器,发现它的cookie是正常添加的. ... 难 ...
- Chrome浏览器查看cookie
原文:http://jingyan.baidu.com/article/6b18230954dbc0ba59e15960.html 1. 查看页面的cookie 方法: a). 点击地址栏前面的文档薄 ...
- 谷歌浏览器和火狐浏览器如何查看HTTP协议
谷歌浏览器和火狐浏览器如何查看HTTP协议 谷歌浏览器查看HTTP协议 火狐浏览器查看HTTP协议
- 删除浏览器浏览器删除cookie方法
上班之余抽点时光出来写写博文,希望对新接触的朋友有帮助.今天在这里和大家一起学习一下删除浏览器 文章目录导航 适用范围及演示工具 什么是cookie? cookie有什么作用? ie6/ie7/ie8 ...
- 火狐浏览器Firefox 如何下载网页的SWF视频,硅谷动力的网站视频怎么下载
1 使用火狐浏览器查看到底视频在哪里,我随便开了一段视频,发现这个SWF(外框套了一个Control.swf,内层才是真实的09-class.swf) 2 我们从下面这一段代码中进行分析 < ...
- 我给女朋友讲编程CSS系列(3) CSS如何设置字体的类型、大小、颜色,如何使用火狐浏览器的Firebug插件查看网页的字体
一.CSS如何设置字体的类型.大小.颜色 设计网页时,一般设置body的字体,让其他标签继承body的字体,这样设置特别方便,但是标题标签h1到h6和表单标签(input类型)是没有继承body的字体 ...
- 转:Chrome浏览器查看网站登录 Cookie 信息的方法
当我们使用自动签到等程序的时候一般都要用到网站Cookie,我们可以借助浏览器的扩展来获取Cookie信息,但其实通过浏览器本身的功能就可以查看Cookie信息.以Chrome类浏览器为例有以下三种方 ...
随机推荐
- ubuntu自带的gedit编辑器添加Markdown预览插件
gedit安装Markdown Preview Ubuntu自带的gedit编辑器也是有很强大的功能的,且支持插件的安装.对于喜欢用Markdown的我来说,这当然是很好的了,gedit本身 就支持M ...
- Centos7 配置网络步奏详解
Centos7 配置网络步奏详解 编辑网卡配置文件 vi /etc/sysconfig/network-script/ifcfg-ens01 备注:这里的ens01不是所有系统都叫这个,有的可能叫其他 ...
- linux安装hadoop 1.2.1
我的服务器里面会装很多东西,所以我在跟目录下面建立了个doc文档文件夹 1.创建存放软件的doc文件夹 mkdir doc 2.进去doc文件夹进行下载hadoop-1.2.1资源包或者到我的百度云下 ...
- iBus
0.闲言 闲来无事,重新玩玩Ubuntu,于是先把Ubuntu13.04删了(为什么是13.04?我也不知道)翻出14.04U盘安装,还算顺利,就是不知道为什么DiskGenius为什么一直提示分区表 ...
- memcpy函数
实现1:<高质量c++,c编程指南> void *mymemcpy(void *dst,const void *src,size_t num) { assert((dst!=NULL)&a ...
- 快速理解Kafka分布式消息队列框架
作者:刘旭晖 Raymond 转载请注明出处 Email:colorant at 163.com BLOG:http://blog.csdn.net/colorant/ ==是什么 == 简单的说,K ...
- js立即执行函数: (function ( ){...})( ) 与 (function ( ){...}( )) 有区别?
没有区别. 你需要明白 IIFE 的原理,我简单说一下: function foo() {...} // 这是定义,Declaration:定义只是让解释器知道其存在,但是不会运行. foo(); / ...
- UVALive 6093 Emergency Room --优先队列实现的模拟
题意:给n个医生,这些医生有一个上班时间,然后给一些病人,病人有一个到达的时间,以及一些诊断,诊断有property(优先级)和duration(诊断时间)这两个属性,每个病人可能要诊断多次,最后问每 ...
- maven 多工程搭建演示
maven出现后,很多公司会用maven来构建项目,单仅仅只是单项目单工程的 并没有使用多工程来构建,这样在以后,项目越来越大,业务越来越多以后,项目会难以维护,越发庞大,维护成本提高,团队士气也会下 ...
- java 8-7 接口
1. 接口的特点: A:接口用关键字interface表示 interface 接口名 {} B:类实现接口用implements表示 class 类名 implements 接口名 {} C:接口不 ...