News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

IP and MAC table

Started by six_L, March 15, 2005, 11:09:02 AM

Previous topic - Next topic

six_L

hello,all
I'm learning a code which can get Local net IP and MAC table. written by others. he said: if it been limited the thread numbers, the code will work. but i'v tested long times, it can't run. Please help me.

;@echo off
;goto make
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.386
.model flat, stdcall
option casemap :none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\iphlpapi.inc
include \masm32\include\ws2_32.inc
include \masm32\include\masm32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\iphlpapi.lib
includelib \masm32\lib\ws2_32.lib
includelib \masm32\lib\masm32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.CONST
   szMacFmt db "%s",9,"%02X:%02X:%02X:%02X:%02X:%02X",13,10,0
   pzCaption db "test",0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.DATA
   dwThread  dd 0
   dwAddrf_r dd 0C0A80101h
   dwAddrt_r dd 0C0A801FFh
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.DATA?
   lpObjarr  dd ?
   stCS CRITICAL_SECTION {?}
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.CODE
;Get Local Net IP and MAC Function About Corresponding Relation
Arp_IP2MAC proc dwIpaddr:DWORD
LOCAL pulMac[8]:BYTE
LOCAL ulLen:DWORD
LOCAL lpMacbuf,lpIpbuf:DWORD
LOCAL dwWritten:DWORD

mov ulLen,6
invoke SendARP,dwIpaddr,0,ADDR pulMac,ADDR ulLen
.IF ulLen != 0
invoke GlobalAlloc,GPTR,4000
mov lpMacbuf,eax
invoke inet_ntoa,dwIpaddr
mov lpIpbuf,eax
xor eax,eax
mov al,pulMac[5]
push eax
mov al,pulMac[4]
push eax
mov al,pulMac[3]
push eax
mov al,pulMac[2]
push eax
mov al,pulMac[1]
push eax
mov al,pulMac[0]
push eax

invoke wsprintf,addr lpMacbuf,addr szMacFmt,addr lpIpbuf
invoke MessageBox,NULL,addr lpMacbuf,addr pzCaption,MB_OK or MB_ICONINFORMATION
invoke EnterCriticalSection,ADDR stCS
invoke GetStdHandle,STD_OUTPUT_HANDLE
push eax
invoke lstrlen,lpMacbuf
pop ecx
lea edx,dwWritten
invoke WriteFile,ecx,lpMacbuf,eax,edx,NULL
invoke GlobalFree,lpMacbuf
invoke LeaveCriticalSection,ADDR stCS
.ENDIF
ret
Arp_IP2MAC endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;Reversing IP Address
ReverseIpaddr proc dwIpaddr:DWORD
LOCAL @dwIp[4]:BYTE
LOCAL @dwIpr[4]:BYTE

mov eax,dwIpaddr
mov DWORD ptr @dwIp,eax
mov al,@dwIp[3]
mov @dwIpr[0],al
mov al,@dwIp[2]
mov @dwIpr[1],al
mov al,@dwIp[1]
mov @dwIpr[2],al
mov al,@dwIp[0]
mov @dwIpr[3],al
mov eax,DWORD ptr @dwIpr
ret
ReverseIpaddr endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:

invoke InitializeCriticalSection,ADDR stCS
mov eax,dwAddrt_r
sub eax,dwAddrf_r
inc eax
sal eax,2
invoke GlobalAlloc,GPTR,eax
mov lpObjarr,eax
mov eax,dwAddrf_r
.WHILE eax <= dwAddrt_r
invoke ReverseIpaddr,eax
mov ecx,eax
invoke CreateThread,NULL,0,addr Arp_IP2MAC,ecx,THREAD_PRIORITY_NORMAL,NULL
mov ecx,lpObjarr
add ecx,dwThread
mov [ecx],eax
inc dwThread
inc dwThread
inc dwThread
inc dwThread
;.break .if dwThread == 10
inc dwAddrf_r
mov eax,dwAddrf_r
.ENDW
sar dwThread,2
invoke WaitForMultipleObjects,dwThread,lpObjarr,TRUE,INFINITE
invoke GlobalFree,lpObjarr
invoke DeleteCriticalSection,ADDR stCS

invoke ExitProcess,0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

end start

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

:make
set name=net_1

    \masm32\bin\ml /c /coff %name%.bat
    \masm32\bin\Link /subsystem:windows %name%.obj
   
    if exist %name%.obj del %name%.obj
    if exist %name%.bak del %name%.bak

regards