免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: yby123
打印 上一主题 下一主题

[C] 如何提前shell中的信息 20分悬赏一下 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-05-22 16:29 |显示全部楼层 |倒序浏览
20可用积分
RT。

比如ping www.baidu.com
返回
PING www.a.shifen.com (220.181.6.19) 56(84) bytes of data.
64 bytes from 220.181.6.19: icmp_seq=0 ttl=54 time=42.4 ms
64 bytes from 220.181.6.19: icmp_seq=1 ttl=54 time=24.9 ms
64 bytes from 220.181.6.19: icmp_seq=2 ttl=54 time=23.7 ms

我现在就像要  from 220.181.6.19  如何做     给出一些代码 谢谢了

论坛徽章:
0
2 [报告]
发表于 2009-05-22 16:38 |显示全部楼层
原帖由 xp5211314 于 2009-5-22 16:35 发表
不妨直接用gethostbyname函数吧

哈哈  不是的。 我就是举个例子。  不是说非要得到ip你说的那个  我以前写过一个 mydns.c   和你说的是一个意思

我现在说 就是想获得终端中的某些内容  是这个想法

论坛徽章:
0
3 [报告]
发表于 2009-05-22 16:46 |显示全部楼层
请问syncpk99 如何控制呢?需要的是其中某些字符啊

#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>

int main()
{
    FILE *fp;
    if ((fp = popen("wget www.baidu.com -O -", "r")) == NULL) {//用“curl www.baidu.com”也是一样的
        perror("popen failed");
        return -1;
    }
    char buf[256];
    while (fgets(buf, 255, fp) != NULL) {
     printf("%s\n", buf);
    }
    if (pclose(fp) == -1) {
        perror("pclose failed");
        return -2;
    }
    return 0;
}

论坛徽章:
0
4 [报告]
发表于 2009-05-22 16:49 |显示全部楼层
原帖由 langue 于 2009-5-22 16:40 发表
拿起鼠标,哗!一选就中。


哎,没办法啊。就是因为没鼠标 我才这样想的。每次发帖回帖 都是  用 tab 来选择的  很累

这段时间CS的排名也下去了。没办法,只能用 小光标键来移动准星

论坛徽章:
0
5 [报告]
发表于 2009-05-22 16:57 |显示全部楼层
原帖由 syncpk99 于 2009-5-22 16:54 发表
使用strstr函数

可否写一下代码。我上面贴出来的能帮我修改一下吗?

论坛徽章:
0
6 [报告]
发表于 2009-05-22 17:13 |显示全部楼层
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#define MAX_LINE 1024
int main()
{
        FILE *fp;
        int len;
        if ((fp = popen("ls /web | wc -l", "r")) == NULL)
        {
        perror("popen failed");
        return -1;
        }
        char buf[MAX_LINE];
        fgets(buf, 255, fp);
        len=strlen(buf);
        buf[len-1]='\0';
        printf("%s\n", buf);
        int i=atoi(buf);
        printf("i is %d \n",i);

        if (pclose(fp) == -1)
        {
        perror("pclose failed");
        return -2;
        }
        return 0;
}

论坛徽章:
0
7 [报告]
发表于 2009-05-22 17:14 |显示全部楼层
搞定了  哈哈  我的不需要哪些  我开始是写入和读取文本的。这样做效率就高了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP