局域网扫描
来源:互联网 发布:行知实验幼儿园 编辑:程序博客网 时间:2024/05/01 15:29
#include <windows.h>#include <IPHlpApi.h>#include <stdio.h>#pragma comment(lib,"ws2_32")#pragma comment(lib,"Iphlpapi")DWORD WINAPI ThreadProc(LPVOID lpParam);int main(int argc,char *argv[]){ CRITICAL_SECTION cs; InitializeCriticalSection(&cs); printf("LAN MAC Scan ...\r\n"); for (int i = 0; i < 255; i ++) { EnterCriticalSection(&cs); CreateThread(NULL,0,ThreadProc,(LPVOID)i,0,NULL); LeaveCriticalSection(&cs); } DeleteCriticalSection(&cs); return 0;}DWORD WINAPI ThreadProc(LPVOID lpParam){ int i = (int)lpParam; char desIp[16] = { 0 }; lstrcpy(desIp,"192.168.1."); char sub[4] = { 0 }; char tmpIp[16] = { 0 }; u_char arDestMac[6] = {0xff,0xff,0xff,0xff,0xff,0xff}; ULONG ulLen = 6; DWORD ret = 0; wsprintf(sub,"%d",i); lstrcpy(tmpIp,desIp); lstrcat(tmpIp,sub); ret = SendARP(inet_addr(tmpIp),NULL,(ULONG *)arDestMac,&ulLen); if (ret == NO_ERROR) { printf("ip = %15s,mac = ",tmpIp); for (int k = 0; k < 5; k ++) { printf("%02X-",arDestMac[k]); } printf("%02X\r\n",arDestMac[k]); } return 0;}