>h>
#include
int main(int argc, char **argv){
TCHDB *hdb;
int ecode;
char *key, *value;
/* create the object */
hdb = tchdbnew();
/* open the database */
if(!tchdbopen(hdb, "casket.tch", HDBOWRITER | HDBOCREAT)){
ecode = tchdbecode(hdb);
or: %s\n", tchdberrmsg(ecode)); }
fprintf(stderr, "open er
r
/* store records */
if(!tchdbput2(hdb, "foo", "hop") ||
!tchdbput2(hdb, "bar", "step") ||
ecode = tchdbecode(hdb);
!tchdbput2(hdb, "baz", "jump")){
fprintf(stderr, "put error: %s\n", tchdberrmsg(ecode));
}
/* retrieve records */
value = tchdbget2(hdb, "foo");
if(value){
ntf("%s\n", value); fr
pr
iee(value);
} else {
ecode(hdb); fprintf(stde
ecode = tchd brr, "get error: %s\n", tchdberrmsg(ecode));
}
/* traverse records */
tchdbiterinit(hdb);
ernext2(hdb)) != NULL){ value = tch
while((key = tchdbi
tdbget2(hdb, key);
if(value){
value); free(value); }
printf("%s:%s\n", key , free(key);
}
/* close the database */
if(!tchdbclose(hdb)){
code(hdb); fprintf(stder
ecode = tchdb
er, "close error: %s\n", tchdberrmsg(ecode));
}
/* delete the object */
tchdbdel(hdb);
return 0;
}
2)使用网络读写
例:
请参考tokyotyrant-1.1.33\doc下index.html的函数接口说明
#include
#include
#include
#include
int main(int argc, char **argv){
TCRDB *rdb;
int ecode;
char *value;
/* create the object */
rdb = tcrdbnew();
/* connect to the server */
if(!tcrdbopen(rdb, "localhost", 1978)){
ecode = tcrdbecode(rdb);
fprintf(stderr, "open error: %s\n", tcrdberrmsg(ecode));
}
/* store records */
if(!tcrdbput2(rdb, "foo", "hop") ||
!tcrdbput2(rdb, "bar", "step") ||
!tcrdbput2(rdb, "baz", "jump")){
ecode = tcrdbecode(rdb);
fprintf(stderr, "put error: %s\n", tcrdberrmsg(ecode));
}
/* retrieve records */
value = tcrdbget2(rdb, "foo");
if(value){
printf("%s\n", value);
free(value);
} else {
ecode = tcrdbecode(rdb);
fprintf(stderr, "get error: %s\n", tcrdberrmsg(ecode));
}
/* close the connection */
if(!tcrdbclose(rdb)){
ecode = tcrdbecode(rdb);
fprintf(stderr, "close error: %s\n", tcrdberrmsg(ecode));
}
/* delete the object */
tcrdbdel(rdb);
return 0;
}
四、构建密码破解web平台,自动生成数据
1、构建web平台
web界面上我就采用了cmd5的风格,改了下颜色。。不太熟悉美工方面,只能改成这样。。。http://www.00aq.com/md5.php
关键代码:
//md5.php(使用memcached-client.php里面有操作memcached的类,包含之后直接调用,网上都可以下载到)
require_once('memcached-client.php');
include('config.php');
$key = $_POST['key'];
if(isset($key))
{
if(strlen($key) == 32)
{
$key = substr($key, 8, 16);
}
$key = strtolower($key);
$mc = new memcached($links);
$value = $mc->get($key);
if(!isset($value))
{
$value = '未查到';
}
}
?>
//config.php
$links = array(
'servers' => array('192.168.99.111:11111'),
'debug' => false,
'compress_threshold' => 10240,
'persistant' => false
);
?>
2、自动插入密码数据
//autoaddnet.c
#include
#include
#include
#include
#include
int main(int argc, char **argv)
{
TCRDB *rdb;
int ecode;
char *source, *value;
int length = *argv[1] - '0';
//字符长度
int mode = *argv[2] - '0';
//字符组合类型
int len = 0, count = 1, i = 0, tonext_value = 0, no = 0;
int series[62] = {0};
rdb = tcrdbnew();
if(!tcrdbopen(rdb, "192.168.99.111", 11111))
//打开数据库连接
{
ecode = tcrdbecode(rdb);
fprintf(stderr, "open error: %s\n", tcrdberrmsg(ecode));
}
switch(mode)
//选择字符的组合
{
case 1:
source = "1234567890";
break;
case 2:
source = "abcdefghijklmnopqrstuvwxyz";
break;
case 3:
source = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
break;
case 4:
source = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
break;
case 5:
source = "abcdefghijklmnopqrstuvwxyz1234567890";
break;
case 6:
source = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
break;
default:
source = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
break;
}
len = strlen(source); //计算字符长度
for(i = 0; i < length; i++)
{
count *= len;
//计算所有组合的总数
}
for(i = 0; i < count; i++)
{
char word[20] = {0};
//word为组合出的字符串
tonext_value = 1;
word[length] = '\0';
for(no = length-1; no >= 0; no--)
{
word[no] = source[series[no]];
//循环填充word字符数组中的每个字符
series[no] += tonext_value;
if(no>0)
{
if(series[no] == len)
//如果已经到达source末尾则从新开始
{
series[no]=0;
tonext_value=1;
}
else
{
tonext_value=0;
}
}
}
char *md5 = MDString(word);
//word原始字符转换成md5
value = tcrdbget2(rdb, md5);
//得到此MD5在db中的value
*(md5+24) = '\0';
//截取32位md5的8-24位
if(!value)
//如果db中没有此value,进行插入
{
if(!tcrdbput2(rdb, md5+8, word))
{
ecode = tcrdbecode(rdb);
fprintf(stderr, "put error: %s\n", tcrdberrmsg(ecode));
}
printf("%s\n", word);
}
else
{
printf("%s-16 exist\n", word);
free(value);
}
}
if(!tcrdbclose(rdb))
//关闭数据库连接
{
ecode = tcrdbecode(rdb);
fprintf(stderr, "close error: %s\n", tcrdberrmsg(ecode));
}
tcrdbdel(rdb);
//删除数据库对象
return 0;
}
编译方法:
gcc -I. -I/usr/local/include autoaddnet.c -o autoaddnet -L/usr/local/lib -ltokyotyrant -lz -lbz2 -lrt -lpthread -lm -lc
用法:
./autoaddnet length mode
length为字符长度,mode为字符组合
(全文完)
注:http://www.00aq.com/md5.php 提供免费MD5查询,以后还会陆续推出mysql等密码免费查询平台,敬请期待
文章来源:DoDo's Blog
原文地址:http://www.sectop.com/post/69.html