文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>expect c library

expect c library

时间:2006-07-15  来源:nahuat

#include <stdio.h>
#include <stdlib.h>
#include <tcl.h>
#include <expect.h>
#include <expect_tcl.h>

#define HOSTNAME    "192.168.0.254"
#define PASSWORD    "cisco\r"

extern char *ptsname(int);

int
main(int argc, char *argv[])
{
    Tcl_Interp *tcl;

    tcl = Tcl_CreateInterp();
    if (Expect_Init(tcl) != TCL_OK)
    {
        puts("failure");
        return 1;
    }

    int fd = exp_spawnl("telnet", "telnet", HOSTNAME, 0);
    if (fd < 0)
    {
        puts("exp_spawnl");
        return 1;
    }

    fclose(stdout);

    int match, loop;
    loop = 1;
    while (loop)
    {
        match = 1;
        switch (exp_expectl(fd, exp_exact, "Password: ", 1, exp_exact, "Warwik>", 2, exp_end))
        {
            case 1:
                write(fd, PASSWORD, sizeof(PASSWORD) - 1);
                break;
            case 2:
                write(fd, "exit\r", 5);
                break;
            case EXP_EOF:
                loop = 0;
                break;
            default:
                match = 0;
                break;
        }
        if (match)
        {
            match = (int)exp_buffer_end - (int)exp_buffer;
            fprintf(stderr, "%.*s", match, exp_buffer);
        }
    }
    return 0;
}

文件: srpbot.tar.bz2
大小: 8KB
下载: 下载
相关阅读 更多 +
排行榜 更多 +
萌趣贪吃蛇

萌趣贪吃蛇

休闲益智 下载
粘液快跑

粘液快跑

休闲益智 下载
火柴人超级战车安卓版

火柴人超级战车安卓版

飞行射击 下载