ok well this is the code im using to get a ip in dword form. and i am using it to ping that address. my problem is that i need to convert the dword back into a ascii ip address. it works 100% on 127.0.0.1. but higher or lower numbers result in diffrent numbers and incompelte ascii ip address. i also post code that i use to convert it , but it doesnt work outside of 127. ive tried for hours to fix it but i am lost.


.data
HostIP db "127.0.0.1",0
ier ICMP_ECHO_REPLY <>
OK db "Ping OK!",0
Fail db "Ping failed!",0
Message db "Ping Address: ";,13,10
addressX db 32 dup (0)

Number db 12 dup (0)
Number1 db 12 dup (0)
Number2 db 12 dup (0)
Number3 db 12 dup (0)
Number4 db 12 dup (0)
.code
invoke inet_addr,addr HostIP
invoke Ping,eax,200,addr ier

.if !eax

pop eax
xor edx,edx
mov ebx,16777216
div ebx
push edx
invoke dwtoa,eax,addr Number;3

pop eax
xor edx,edx
mov ebx,65535
div ebx
push edx
invoke dwtoa,eax,addr Number1;0

pop eax
xor edx,edx
mov ebx,255
div ebx
push edx
invoke dwtoa,eax,addr Number2;0

pop eax
invoke dwtoa,eax,addr Number3;127
;int 3
invoke lstrlen,addr Number3

mov edx,offset addressX
mov edi, offset Number3
xor ebx,ebx
mov cl,byte ptr [edi+ebx]
mov byte ptr [edx+ebx],cl
inc ebx
cmp ebx,eax
pushfd
dec ebx
popfd
je @1
@@:
inc ebx
mov cl,byte ptr [edi+ebx]
mov byte ptr [edx+ebx],cl
cmp ebx,eax
jne @B
@1:
add edx ,ebx
mov byte ptr [edx],"."
inc edx
push edx
invoke lstrlen,addr Number2
pop edx
mov edi, offset Number2
xor ebx,ebx
mov cl,byte ptr [edi+ebx]
mov byte ptr [edx+ebx],cl
inc ebx
cmp ebx,eax
pushfd
dec ebx
popfd
je @2

@@:
inc ebx
mov cl,byte ptr [edi+ebx]
mov byte ptr [edx+ebx],cl
cmp ebx,eax
jne @B
@2:
add edx ,ebx
inc edx
mov byte ptr [edx],"."
inc edx
push edx
invoke lstrlen,addr Number1
pop edx
mov edi, offset Number1
xor ebx,ebx
mov cl,byte ptr [edi+ebx]
mov byte ptr [edx+ebx],cl
inc ebx
cmp ebx,eax
pushfd
dec ebx
popfd
je @3

@@:
inc ebx
mov cl,byte ptr [edi+ebx]
mov byte ptr [edx+ebx],cl
cmp ebx,eax
jne @B
@3:
add edx ,ebx
inc edx
mov byte ptr [edx],"."
inc edx
push edx
invoke lstrlen,addr Number
pop edx
mov edi, offset Number
xor ebx,ebx
mov cl,byte ptr [edi+ebx]
mov byte ptr [edx+ebx],cl
inc ebx
cmp ebx,eax
pushfd
dec ebx
popfd
je @4

@@:
inc ebx
mov cl,byte ptr [edi+ebx]
mov byte ptr [edx+ebx],cl
cmp ebx,eax
jne @B
@4:
; is printed to text after this
Posted on 2002-07-28 23:11:55 by Qages
inet_addr
Posted on 2002-07-29 00:08:25 by comrade

inet_addr


LOL!
He used inet_addr to get the Dword from the IP :) (look again at his source)

Qages,
try this:



; szMask db "%lu.%lu.%lu.%lu", 0

mov eax, nIP

mov ebx, eax ; first part
shr ebx, 24
and ebx, 255
push ebx

mov ebx, eax ; second part
shr ebx, 16
and ebx, 255
push ebx

mov ebx, eax ; third part
shr ebx, 8
and ebx, 255

and eax, 255 ; fourth part

pop ecx
pop edx

invoke wsprintf, addr szBuffer, addr szMask, edx, ecx, ebx, eax
invoke MessageBox, hWin, addr szBuffer, 0, 0

Posted on 2002-07-29 01:12:21 by bazik
inet_ntoa then. Either way, winsock has functions to do conversions both ways.
Posted on 2002-07-29 02:08:50 by comrade
thanks bAZiK,
Posted on 2002-07-29 13:13:31 by Qages