C语言能获取当前IP吗

发布网友 发布时间:2022-04-22 07:40

我来回答

2个回答

热心网友 时间:2022-06-17 21:58

#include "stdio.h"
#include "conio.h"
main()
{
int i,j;
char ip[20];
char temp[100];
char ch='\0';
FILE *fp;
system("ipconfig >d:\\myip.txt");
if ((fp=fopen("d:\\myip.txt","r"))==NULL)
{
printf("the file can not open:\nPress any key to exit:");
getch();
exit(1);
}
for (i=0;i<7;i++)
{fgets(temp,80,fp); /*跳过一些行*/
/*printf("%s\n",temp); */}
fgets(temp,80,fp);
i=0;j=0;
while (temp[i++]!=':')
;
while (temp[i]!='\n')
ip[j++]=temp[i++];
ip[j]=0;
printf("IP=%s\n",ip);
fclose(fp);
system("del d:\\myip.txt");

getch();
}

热心网友 时间:2022-06-17 21:58

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com