Use the IP Helper API to get a program of computer MAC address in the LAN

xiaoxiao2021-03-06  53

In the process of ARP spoofing, first, the MAC address of the target computer can be obtained, and the MAC address of the target computer can be obtained by publishing an ARP request in a local area network, and can also be obtained by the case of surviving hosts in the local area network.

The program code is as follows:

// vin1.cpp: defines the entry point for the console application.//

#include "stdafx.h"

#include #include #include #include "winsock2.h" #include #include # Pragma Comment (lib, "ws2_32.lib") # pragma Comment (lib, "iphlpapi.lib") uint bvbose = 0;

Bool isactive; Void usage (char * pdestip); uint nn (int nbase, int npoint); BOOL LongtoString (uint nip, char ** PRET); int __cdecl main Int argc, char * argv []) {ulong uStartip = 0, undip = 0; // 0xbe68f0f3 0x0bddca0d if (argc! = 2 && argc! = 3 && argc! = 4) {usage (argv [0]); Return 0;} if (argc == 2) {if (! Strcmp (argv [1], "- v")) {usage (argv [0]); return 0;} uStartip = TRANTOLONG (Argv [1]); Undip = uStartip;} else if (argc == 3) {if (! strcmp (argv [1], "- v")) {BVBOSE ; uStartip = trantolong (argv [2]); undip = uStartip; bvbose ;} else {uStartip = trantolong (argv [1]); uendip = trantolong (argv [2]);}}}} else if (argc == 4) {if (! Strcmp (argv [1], "- V ")) {BVBOSE ;} else {usage Argv [0]); RETURN 0;} uStartip = trantolong (argv [2]); undip = trantolong (argv [3]);} if (uStiP - uStartip <0) {uStartip = uendip; uStiP = uStartip - Uendip Ustartip = uStartip - undip;} char szbuf [64]; char * ptemp = szbuf; for (uint i = ustartip; i <= uendip; i ) {longTostring (I, & ptemp); isactive (szbuf);} Return 0;}

Bool Isactive (Char * pdestip) {HRESULT HR; ipaddr ipaddr; ulong pulmac [2]; ulong ullen; if (pdestip == null || strlen (pdestip) == 0) {IF (bvbose) {printf ("Input Error , The Input IP Address IS [} RETURN FALSE;}}}}}}}}}}}}}}}}}}}}}}}}; ipAddr == INADDR_NONE) {if (bvbose) {Printf ("Input Error, THE INPUT IP Address IS [% S] / R / N ", PDestip; Return False;}} Memset (Pulmac, 0xFF, SIZEOF (PULMAC)); ullen = 6; HR = Sendarp (iPaddr, 0, Pulmac, & Ullen !); if (hr = NO_ERROR) {if (bVbose) {printf ( "IP Address:% s <===>", pDestIp); LPVOID lpMsgBuf; if (FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, hr, Makelangid (lang) _Neutral, sublang_default 08X, Length% 8D / N ", HR, ULLEN); size_t i, j; char * szmac = new char [ullen * 3]; PBYTE PBHEXMAC = (PBYTE) Pulmac; /// Convert the binary Mac Address Into Human -readable // for (i = 0, j = 0; i

} Printf ("IP Address:% S <====>", PDestip); Sprintf (SZMAC J, "% 02x", PBHEXMAC [I]); Printf ("Mac Address% S / R / N", SZMAC ); Delete [] szmac; return true;} void usage ("You can use the program to detect if the machine is active./r/n"); Printf ("and get the machine Mac Address / R / N "); Printf ("% S USAGE: / R / N% s DESZP / R / N% s Startip Endip / R / N ", PSZPROM, PSZPROM, PSZPROM);} uint Trantolong (char * PDestip) {if (pdestip == null || strlen (pdestip) == 0) {return -1;} int ndot = 0; int NTEMP = 0; uint nret = 0; char * ptemp = pdestip; while (NDOT < 3) {while (* ptemp! = '.') {PTEMP ;} * ptemp = '/ 0'; ntemp = atoi (pdestip); NRET = NTEMP * NN (255, 3 - ndot); NDOT ; Pdestip = ptemp 1; ntemp = 0;} ntemp = atoi (pdestip); nret = ntemp; return nret;} uint nn (int nbase, int npoint) {uint ntmep = 1; fo R (int i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-115150.html

New Post(0)