VC實現(xiàn)將網(wǎng)址解析出所有ip地址的實例代碼
更新時間:2021年04月01日 10:33:16 作者:小道安全
這篇文章主要介紹了VC實現(xiàn)將網(wǎng)址解析出所有ip地址的實例代碼,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
通過調(diào)用gethostbyname 系統(tǒng)函數(shù)進行解析
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地址寫入到文件中
//寫文件,第一個參數(shù)文件名,第二個參數(shù)hostName,第三個參數(shù)文件內(nèi)容 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) { //文件創(chuàng)建失敗 return; } if(SetFilePointer(hFILE,0,NULL,FILE_END)==-1) { printf("SetFilePointer error\n"); return ; } DWORD dwhostWrite; if(!WriteFile(hFILE,hostName,strlen(hostName),&dwhostWrite,NULL)) { printf("WriteFile error\n"); return ; } if(!WriteFile(hFILE,"\r\n",2,&dwhostWrite,NULL)) { printf("WriteFile error\n"); return ; } DWORD dwWrite; if(!WriteFile(hFILE,text,strlen(text),&dwWrite,NULL)) { printf("WriteFile error\n"); return ; } if(!WriteFile(hFILE,"\r\n",2,&dwWrite,NULL)) { printf("WriteFile error\n"); return ; } CloseHandle(hFILE); }
到此這篇關(guān)于VC實現(xiàn)將網(wǎng)址解析出所有ip地址的文章就介紹到這了,更多相關(guān)vc實現(xiàn)網(wǎng)址解析ip地址內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:
相關(guān)文章
Linux下實現(xiàn)C++操作Mysql數(shù)據(jù)庫
由于工作需要抽出一周的時間來研究C/C++訪問各種數(shù)據(jù)庫的方法,并打算封裝一套數(shù)據(jù)庫操作類,現(xiàn)在奉上最簡單的一部分:在Linux下訪問MySQL數(shù)據(jù)庫。2017-05-05c++ 內(nèi)聯(lián)函數(shù)和普通函數(shù)的區(qū)別
內(nèi)聯(lián)函數(shù)是c++為了提高程序的運行速度做的改進,那么內(nèi)聯(lián)函數(shù)和普通函數(shù)的區(qū)別是什么,本文就來詳細的介紹一下,感興趣的朋友可以了解一下2021-05-05數(shù)據(jù)結(jié)構(gòu)之AVL樹詳解
這篇文章主要介紹了數(shù)據(jù)結(jié)構(gòu)之AVL樹詳解,本文非常細致的講解了AVL樹的基礎(chǔ)知識、AVL樹的旋轉(zhuǎn)操作、AVL數(shù)的插入和刪除操作等,需要的朋友可以參考下2014-08-08