邪恶八进制信息安全团队技术讨论组's Archiver

EvilOctal 2005-7-31 11:17

[转载]获取本机IP地址代码

原始连接:[url]http://www.blacksky.cn/article.asp?id=408[/url]

[code]////////////////////以下代码在VC++ 6.0 + SP6直接编译成功



#include <stdio.h>

#include <winsock2.h>



#pragma comment( lib, "WS2_32.lib" ) //很多人就是因为这个编译不成功 :)



int main()

{

char host_name[256];

int WSA_return;

WSADATA WSAData;

HOSTENT *host_entry;

WORD wVersionRequested;



wVersionRequested = MAKEWORD( 2, 0 );

WSA_return=WSAStartup(wVersionRequested,&WSAData); //进行WSAStartup函数调用



if(WSA_return==0)

{

gethostname(host_name,sizeof(host_name)); //获取本地主机名称

host_entry=gethostbyname(host_name); //从主机名数据库中得到对应的“主机”



  for( int i = 0; host_entry!= NULL && host_entry->h_addr_list[i]!= NULL; i++ )

    //循环得出本地机器所有IP地址

  {

    const char *pszAddr=inet_ntoa (*(struct in_addr *)host_entry->h_addr_list[i]);

MessageBox(NULL,pszAddr,host_name,MB_OK);

  }



}

else

{

  //错误提示

printf("ERROR !\n");

}



WSACleanup();

return 0;

} [/code]

sirprise 2005-10-15 19:59

不行啊
c:\documents and settings\xpsniper\桌面\a.c(47) : error C2143: syntax error : missing &#39;;&#39; before &#39;type&#39;
c:\documents and settings\xpsniper\桌面\a.c(47) : error C2143: syntax error : missing &#39;;&#39; before &#39;type&#39;
c:\documents and settings\xpsniper\桌面\a.c(47) : error C2143: syntax error : missing &#39;)&#39; before &#39;type&#39;
c:\documents and settings\xpsniper\桌面\a.c(47) : error C2143: syntax error : missing &#39;;&#39; before &#39;type&#39;
c:\documents and settings\xpsniper\桌面\a.c(47) : error C2065: &#39;i&#39; : undeclared identifier
c:\documents and settings\xpsniper\桌面\a.c(47) : error C2059: syntax error : &#39;)&#39;
c:\documents and settings\xpsniper\桌面\a.c(51) : error C2143: syntax error : missing &#39;;&#39; before &#39;{&#39;

页: [1]
© 1999-2008 EvilOctal Security Team