ping服务器并检查C程序的结果? [英] Ping servers and check the result from C program?

查看:145
本文介绍了ping服务器并检查C程序的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的最后一个问题.现在,我的新要求是对一组服务器执行ping操作,并检查它们是否在答复.我正在尝试

This is My last question. Now my new requirement is to ping some set of servers and check if they are replying or not. I am trying my way of

system("ping xxx.xx.xx.xx >out.txt");

然后解析out.txt以获取字符串请求超时". 这给我带来了很好的结果.但是有什么更好的方法可以从c程序中执行.也欢迎使用非编程方式.但是我主要想通过C程序去.如果请求超时,我将以同样的方式通过php发送邮件.提前致谢.

我的环境:Windows,Tiny C编译器

And then parsing the out.txt for a string "Request timed out.". This is yielding me good results. But is there any better way to do from c program. Non programmatic ways are also welcome. But mostly I want to go by C program. If the request is timed out I will send a mail through same my way by php. Thanks in advance.

My environment : windows, Tiny C Compiler

推荐答案

system()更好的捕获输出的方法是使用popen().这样,您无需使用临时文件即可捕获命令的输出.

A better method for capturing output than system() is to use popen() instead. That way you can capture the output of the command without using a temporary file.

一种更好的ping方法是使用Microsoft ICMP API(可以在介绍页面中找到此处).如果您的C编译器能够调用任意Win32 API函数,则这将是可能的.特别是, IcmpSendEcho 是您要使用的功能想要.

A better method for pinging is to use the Microsoft ICMP API (an introductory page can be found here). This will be possible if your C compiler has the ability to call arbitrary Win32 API functions. In particular, IcmpSendEcho is the function you would want.

这篇关于ping服务器并检查C程序的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆