最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
VC实现将网址解析出所有ip地址代码实例
时间:2022-06-25 04:29:22 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下VC实现将网址解析出所有ip地址代码实例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
通过调用gethostbyname 系统函数进行解析
void GetHostNamebyIp(char* hostName)
{
if(NULL == hostName)
{
return;
}
int WSA_return = 0;
WSADATA WSAData;
HOSTENT *host_entry;
char szIP[1024] = {0};
AfxMessageBox(hostName);
WSA_return=WSAStartup(0x0202,&WSAData);
if(0 == WSA_return)
{
host_entry = gethostbyname(hostName);
if(0 != host_entry)
{
char** ipAddress = host_entry->h_addr_list;
for(; *ipAddress != NULL; ipAddress++)
{
strcpy(szIP,inet_ntoa(*(LPIN_ADDR)*(ipAddress)));
WriteIPFile("ip.txt",hostName ,szIP);
}
}
}
}
将解析出来的ip地址写入到文件中
//写文件,第一个参数文件名,第二个参数hostName,第三个参数文件内容
void WriteIPFile(char* FileName, char* hostName, char* text)
{
HANDLE hFILE=CreateFile(FileName,GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if(hFILE==INVALID_HANDLE_VALUE)
{
//文件创建失败
return;
}
if(SetFilePointer(hFILE,0,NULL,FILE_END)==-1)
{
printf("SetFilePointer errorn");
return ;
}
DWORD dwhostWrite;
if(!WriteFile(hFILE,hostName,strlen(hostName),&dwhostWrite,NULL))
{
printf("WriteFile errorn");
return ;
}
if(!WriteFile(hFILE,"rn",2,&dwhostWrite,NULL))
{
printf("WriteFile errorn");
return ;
}
DWORD dwWrite;
if(!WriteFile(hFILE,text,strlen(text),&dwWrite,NULL))
{
printf("WriteFile errorn");
return ;
}
if(!WriteFile(hFILE,"rn",2,&dwWrite,NULL))
{
printf("WriteFile errorn");
return ;
}
CloseHandle(hFILE);
}
相关文章
- 斗罗大陆零朱竹青有什么技能 12-31
- 猫耳fm网页版一键登录-猫耳FM网页版快捷入口 12-31
- 吉星派对南希露基强度怎么样 12-31
- 妖精漫画免费下载最新版本安装-妖精漫画免费浏览下载入口完整合集 12-31
- 云原神官网正式上线-云原神破解版免费畅玩 12-31
- 绝区零叶瞬光有什么玩法技巧 12-31