// GetLANIP.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <afxtempl.h> #include <WINSOCK2.H> #pragma comment(lib,"Ws2_32.lib") #pragma comment(linker, "/defaultlib:kernel32.lib") #pragma comment(linker, "/OPT:NOWIN98") int GetHostList(CStringArray& caHostList); int main(int argc, char* argv[]) { // printf("Hello World!/n"); CStringArray caHostList; int nNumOfhosts=0; nNumOfhosts = GetHostList(caHostList); printf("Number of Hosts: %d/n",nNumOfhosts); for(int i=0;i<nNumOfhosts;i++) { printf("%s",caHostList[i]); } system("pause");//暂停屏幕 return 0; } int GetHostList(CStringArray& caHostList) { WORD wsaVersion; WSADATA WSAData; wsaVersion=MAKEWORD(2,0); if(WSAStartup(wsaVersion,&WSAData)==SOCKET_ERROR) { return 0; } FILE *bat=fopen("host.bat","wb"); if(bat==NULL) return 0; fputs("@echo off/r/n",bat); fputs(