Mấy cái đấy em tự làm chứ, đơn giản mà
// crt_popen.c
/* This program uses _popen and _pclose to receive a
* stream of text from a system process.
*/
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char psBuffer[1000];
FILE *pPipe;
/* Run DIR so that it writes its output to a pipe. Open this
* pipe with read text attribute so that we can read it
* like a text file.
*/
char website[1000];
char command[1000];
printf("Nhap vao dia chi web muon lay IP: ");
fgets(website, 1000, stdin);
sprintf_s(command, 1000, "ping %s -n 1 -4", website);
if ((pPipe = _popen(command, "rt")) == NULL)
exit(1);
/* Read pipe until end of file, or an error occurs. */
while (fgets(psBuffer, 1000, pPipe))
{
char ip[20];
for (int i = 0; i < 1000; ++i) {
if (psBuffer[i] == '[') {
++i;
while (psBuffer[i + 1] != ']') {
putchar(psBuffer[i++]);
}
putchar(psBuffer[i]);
break;
}
}
}
/* Close pipe and print return value of pPipe. */
if (feof(pPipe))
{
printf("\nProcess returned %d\n", _pclose(pPipe));
}
else
{
printf("Error: Failed to read the pipe to the end.\n");
}
}