C/C++ PING code

把SendARP部分换成ping功能函数就可以  其实不换也可以

C/C++ code
    
    
    
    
#include < stdio.h > #include < windows.h > #include < winsock2.h > #include < iphlpapi.h > #pragma comment (lib, "ws2_32.lib" ) #pragma comment (lib, "Iphlpapi.lib") DWORD WINAPI TestThread(LPVOID lParam) { int n = ( int )(INT_PTR)lParam; IPAddr ip = inet_addr( " 192.168.0.0 " ) + (n << 24 ); BYTE mac[ 8 ]; ULONG len = sizeof (mac); if (SendARP(ip, 0 , (PULONG)mac, & len) == NO_ERROR) { printf( " 192.168.0.%d : %02X-%02X-%02X-%02X-%02X-%02X/n " , n, mac[ 0 ], mac[ 1 ], mac[ 2 ], mac[ 3 ], mac[ 4 ], mac[ 5 ]); } return 0 ; } void main() { HANDLE h[ 255 ]; for ( int i = 1 ; i < 255 ; i ++ ) { h[i] = CreateThread(NULL, 0 , TestThread, (PVOID)(INT_PTR)i, 0 , NULL); } for ( int j = 1 ; j < 255 ; j ++ ) { WaitForSingleObject(h[j], - 1 ); CloseHandle(h[j]); } }

你可能感兴趣的:(C/C++ PING code)