struct PINGS
{
	HANDLE icmp_handle;
	dword echo_reply;
	dword baseip;
	dword scaning;
	BYTE buffer[60];
	void InitPing(dword bip);
	void Ping();
	void EndPing();
};

void PINGS::InitPing(dword bip)
{
	$push EDI
	scaning=FALSE;
	IF(icmp_handle=IcmpCreateFile()!=INVALID_HANDLE_VALUE){
		echo_reply=GlobalAlloc(GMEM_FIXED,sizeof(ICMP_ECHO_REPLY)+59);
		baseip=bip;
		scaning=TRUE;
	}
	$pop EDI
}

void PINGS::Ping()
{
char buf[80];
int i;
union{
	int ip;
	byte ipb[4];
};
word mac[3];
	$push EDI
	if(scaning){
		for(i=2;i<255;i++){
			ip=i<<24+baseip;
			ESI=echo_reply;
			ESI.ICMP_ECHO_REPLY.Options.Ttl=100;
			ESI.ICMP_ECHO_REPLY.Data=#buffer;
			ESI.ICMP_ECHO_REPLY.DataSize=59;
			IcmpSendEcho(icmp_handle,ip,#buffer,59,NULL,ESI,sizeof(ICMP_ECHO_REPLY)+59,1000);
			IF(EAX){
				WHILE(busygetmac)Sleep(0);
				GetMAC(ip,#mac);
				ESI=echo_reply;
				wsprintf(#buf,"%d.%d.%03d.%03d - %04X%04X%04X %dms\n",
					ipb,ipb[1],ipb[2],ipb[3],
					mac,mac[2],mac[4],ESI.ICMP_ECHO_REPLY.RoundTripTime);
				WriteInfo(#buf);
			}
		}
		scaning=FALSE;
	}
	$pop EDI
}

void PINGS::EndPing()
{
	$push EDI
	GlobalFree(echo_reply);
	IcmpCloseHandle(icmp_handle);
	$pop EDI
}
