Home > Software engineering >  Use vs2010 MFC implementation using the icmp protocol search activity in a network host
Use vs2010 MFC implementation using the icmp protocol search activity in a network host

Time:10-17


For network programming is confused, ask,,,

Design process, its function is to send ICMP packet, for local area network (LAN) activities in the host, and the results show that the vs2010 MFC graphical interface, can be directly run,,,

CodePudding user response:

network using ICMP found within the LAN host

CodePudding user response:

http://wenku.baidu.com/link? Url=ImEIZVy3K8W31FWMo95ePzCZdKz5TJ6UcMH3b - 5 lfft8ldaaqhzpqvinrcchgqjfiyh5bnd7vvaahmrtrxs - BcnkHlv5wPjanegGRKLYegW

CodePudding user response:

reference 1st floor zgl7903 response:
network using ICMP found within the LAN host

I need the IP address to its operation results output on a graphical interface, is to use the results on the MFC graphical interface,,, this report is not a graphical interface, above,

CodePudding user response:

http://wangbaiyuan.cn/c-activity-host-scans.html
Your own modified into the console GUI can, should or simple ~

CodePudding user response:

See the MSDN routine SendARP ()

ms-help://MS.MSDNQTR.v90.chs/iphlp/iphlp/sendarp.htm

 
//The following code demonstrates how to obtain The hardware or media access control (MAC) address associated with a specified IPv4 address.

/* sendarp. C
*
* Link with wsock2. Lib and iphlpapi. Lib
*/

#include
#include
#include

Void the usage (char * pname)
{
Usage: printf (" % s [options] IP address - \ n ", pname);
Printf (" \ t - h \ \ t thelp \ n ");
Printf (" \ t - length l \ tMAC physical address length to set \ n ");
Printf (" \ SRC \ t - s - IP tsource IP address \ n ");
exit(1);
}

Int __cdecl main (int arg c, char * * argv)
{
DWORD dwRetVal;
IPAddr DestIp=0;
IPAddr SrcIp=0;/* the default for the SRC IP */
ULONG MacAddr [2]./* for 6 - byte hardware addresses */
ULONG PhysAddrLen=6;/* the default to the length of the six bytes */

Char * DestIpString=NULL;
Char * SrcIpString=NULL;

BYTE * bPhysAddr;
int i;

If (arg c & gt; 1) {
For (I=1; I & lt; Arg c; I++) {
If ((argv [I] [0]=='-') | | (argv [I] [0]=='/')) {
The switch (tolower (argv [I] [1])) {
Case 'l' :
PhysAddrLen=(ULONG) atol (argv [+ +] I);
break;
In case the 's' :
SrcIpString=argv [I] + +;
SrcIp=inet_addr (SrcIpString);
break;
Case 'h' :
Default:
The usage (argv [0]);
break;
End switch}/* */
} the else
DestIpString=argv [I];
}/* end for */
} the else
The usage (argv [0]);

If (DestIpString==NULL | | DestIpString [0]=='\ 0')
The usage (argv [0]);

DestIp=inet_addr (DestIpString);

Memset (& amp; MacAddr, 0 XFF, sizeof (MacAddr));

Printf (" Sending ARP request for IP address: % s \ n ", DestIpString);

DwRetVal=SendARP (DestIp, SrcIp, & amp; MacAddr, & amp; PhysAddrLen);

If (dwRetVal==NO_ERROR) {
BPhysAddr=(BYTE *) & amp; MacAddr;
If (PhysAddrLen) {
for (i=0; I & lt; (int) PhysAddrLen; I++) {
If (I==(PhysAddrLen - 1))
Printf (" % 2 x \ n ", (int) bPhysAddr [I]);
The else
Printf (" % 2 x - ", (int) bPhysAddr [I]);
}
} the else
Printf
(" Warning: SendArp completed successfully, but returned length=0 \ n ");

} else {
Printf (" Error: SendArp failed with Error: % d ", dwRetVal);
The switch (dwRetVal) {
Case ERROR_GEN_FAILURE:
Printf (" (ERROR_GEN_FAILURE) \ n ");
break;
Case ERROR_INVALID_PARAMETER:
Printf (" (ERROR_INVALID_PARAMETER) \ n ");
break;
Case ERROR_INVALID_USER_BUFFER:
Printf (" (ERROR_INVALID_USER_BUFFER) \ n ");
break;
Case ERROR_BAD_NET_NAME:
Printf (" (ERROR_GEN_FAILURE) \ n ");
break;
Case ERROR_BUFFER_OVERFLOW:
Printf (" (ERROR_BUFFER_OVERFLOW) \ n ");
break;
Case ERROR_NOT_FOUND:
Printf (" (ERROR_NOT_FOUND) \ n ");
break;
Default:
printf("\n");
break;
}
}

return 0;
}




If using a single thread, will slowly, order sent from 1 to 255,
Can be to multithreaded way in order to save time, divided into 1-64; 65-127; 128-191; Four period of 192-255 interval, with four threads at the same time scanning
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
 
Typedef struct ipmac
{
Char szIp [16].
Char szMac [6].

} IPMAC;
IPMAC host [255].
Int k=0;
CRITICAL_SECTION cs;
IP/* thread function, which is used to query the corresponding MAC address */
DWORD WINAPI ArpThread (LPVOID lParam)
{
Char * szIp=lParam (char *);
ULONG with pMac [2].
ULONG pulen=6;
Int ret.
TRACE (szIp);
If ((ret=SendARP (inet_addr (szIp), 0, with pMac, & amp; Pulen))==0)
{
The EnterCriticalSection (& amp; Cs);//multithreaded synchronization, ha ha: 0
Strcpy (host [k]. SzIp, szIp);
PBYTE PBYTE=(PBYTE) with pMac;
For (int I=0; i<5; I++)
{
The host [k]. SzMac [I]=pbyte [I];
TRACE (" % 02 x - "and pbyte [I]);
}
TRACE (" % 02 x, "pbyte [5]);
The host [k]. SzMac [5]=pbyte [5].
k++;
LeaveCriticalSection (& amp; Cs);

}
The else
{
TRACE (" SendARP Error % d ", ret);
}
Return 0; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related