this is real sloppy so far i got it to return 192.168.0.1< so i still need it to strip off the remaining < if anyone could help clean it up and chop off the remaining <



; basically what i want to do is connect to [url]http://checkip.dyndns.org/[/url] and get the html soucre of the page
; into a string buffer which would look like
; <html><head><title>Current IP Check</title></head><body>Current IP Address: 192.168.0.1</body></html>
; i want to parse off the beginning junk up to the : in the string so it will look like
; 192.168.0.1</body></html>
; then i want to parse the </body></html> so i have the remaining ip address in the string

.386
.model flat, stdcall
option casemap:none
include C:\masm32\include\kernel32.inc
include C:\masm32\include\user32.inc
include C:\masm32\include\windows.inc
include C:\masm32\include\shell32.inc
includelib C:\masm32\lib\kernel32.lib
includelib C:\masm32\lib\user32.lib
includelib C:\masm32\lib\shell32.lib

Stripper PROTO :DWORD, :DWORD
.data
szURL db "http://checkip.dyndns.org/",0
szIP db "Current IP Address: 192.168.0.1</body></html>",0
.data?
buffer db 256 dup(?)
szBuffer db 256 dup(?)
ipaddr db 64 dup (?)
.code
Start:
;first we have to connect to the url and get the html in a buffer
; since im dumb and dont know how to do that yet ill make a false buffer szIP

invoke Stripper, ADDR szIP, ADDR buffer ; stripper ,the string to strip,the finished string
invoke MessageBox,0,addr szBuffer,0,0
invoke ExitProcess,0

Stripper PROC theString:DWORD, stripped:DWORD
push esi
push edi
push ebx
push eax

mov esi, theString
mov ebx, esi

@@:
lodsb ;Get character
cmp al, 0 ;check if its zero
je EOF ;jump to EOF if 0 is found
cmp al, ':' ;check for last :
jne @b ; if not found jump back up to @@
mov ebx, esi ; save pointer to last found colon
jmp @b ; if not found jump back up to @@

EOF:
mov edi, stripped
mov esi, ebx
@@:
lodsb
stosb ; Store String Byte
cmp al, 0 ;check for last zero
jne @b
mov edi,offset szBuffer
mov esi,stripped ;esi = pointer
@@: ; now its time to strip of the end fat
lodsb ;load byte al
stosb ;store al esi
cmp al,'<' ;is al '<'?
je @F ;yeah, we're done
jmp @B ;nope, repeat
@@:
pop eax ; time for a clean exit :D
pop ebx
pop edi
pop esi
ret
Stripper ENDP

end Start

i wanted the stripper proc to have it be like invoke stripper,addr source,addr dest,addr frontstring,addr rearstring
frontstring would be like the db ":",0
rearstring would be like db " < ",0
that way it can be used with different webpages with different strings to parse

:stupid:
Posted on 2003-12-01 00:25:19 by illwill


Stripper PROC uses esi edi ebx theString:DWORD, stripped:DWORD

mov esi, theString

@@:
cmp BYTE PTR [esi], 0
je _ERROR ;end of string and no :
cmp BYTE PTR [esi], ':'
je @f
inc esi
jmp @b ; if not found jump back up to @@
@@:
inc esi
inc esi ;one space before IP now esi should point to IP.

mov edi, stripped
@@:
lodsb
cmp al, 0
je NoMore
cmp al, '<'
je NoMore
stosb ; Store String Byte
jmp @b
_ERROR:
mov eax, -1 ;function returns -1 if no IP found
ret
NoMore:
[B]inc edi
mov BYTE PTR [edi], 0[/B];bug fix
mov eax, 0
ret
Stripper ENDP
Posted on 2003-12-01 02:16:58 by ENF


stripper:
;first para address to frontstrip
;second para address to rear strip
;third para address to string to scan
;fourth para address to string to store
mov ecx, [esp+4]
mov al, [ecx]
mov ecx, [esp+8]
mov ah, [ecx]
mov ecx, [esp+12]
_findstart:
cmp byte ptr[ecx], al
jz _found
cmp byte ptr[ecx],0
jz _out
inc ecx
jmp _findstart
_found:
inc ecx
push ebx
mov ebx, [esp+16]
_copy:
mov dl, [ecx]
inc ecx
test dl, ah
jz _done
test dl, dl
jz _done
mov [ebx], dl
inc ebx
jmp _copy
_done:
mov byte ptr[ebx+1], 0
pop ebx
clc
retn
_out:
stc ; oops error
retn
;carry flag set on error
;destroys ecx, edx and eax

Untested
Posted on 2003-12-01 02:19:40 by roticv
sloppy but it works... it'll connect to
http://checkip.dyndns.org/ and pull grab the html and parse it til it finds the IP
good for people to get the ip of themselves outside their router


.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

include \masm32\include\wsock32.inc
includelib \masm32\lib\wsock32.lib
includelib \masm32\lib\wininet.lib
include \masm32\include\wininet.inc

Download PROTO :DWORD
Stripper PROTO :DWORD, :DWORD
.data
url1 db "http://checkip.dyndns.org/",0
szIP db "Your WAN IP",0
.data?
buffer db 256 dup(?)
htmlBuffer db 256 dup(?)
.code
Start:

invoke Download,addr url1
invoke Stripper, ADDR htmlBuffer, ADDR buffer ; stripper ,the string to strip,the finished string
invoke MessageBox,0,addr buffer,addr szIP,0
invoke ExitProcess,0

Download PROC lpszURL:DWORD
local hInternet:DWORD
local hURL:DWORD
local hFile:DWORD
;local htmlBuffer[1024]:BYTE
local BufferLen:DWORD
local BytesWrite:DWORD
jmp @F
lpszAgent DB "Mozilla",0
@@:
invoke InternetOpen, addr lpszAgent, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0
mov hInternet, eax
invoke InternetOpenUrl, hInternet, lpszURL, 0, 0, 0, 0
mov hURL, eax
invoke InternetReadFile, hURL, addr htmlBuffer, sizeof htmlBuffer, addr BufferLen

invoke CloseHandle, hFile
invoke InternetCloseHandle, hURL
cmp eax, 0
jz done
invoke InternetCloseHandle, hInternet
xor eax, eax
inc eax
ret
done:
xor eax, eax
ret
Download ENDP

Stripper PROC uses esi edi ebx theString:DWORD, stripped:DWORD

mov esi, theString

@@:
cmp BYTE PTR [esi], 0
je _ERROR ;end of string and no :
cmp BYTE PTR [esi], ':'
je @f
inc esi
jmp @b ; if not found jump back up to @@
@@:
inc esi
inc esi ;one space before IP now esi should point to IP.

mov edi, stripped
@@:
lodsb
cmp al, 0
je NoMore
cmp al, '<'
je NoMore
stosb ; Store String Byte
jmp @b
_ERROR:
mov eax, -1 ;function returns -1 if no IP found
ret
NoMore:
inc edi
mov BYTE PTR [edi], 0;bug fix
mov eax, 0
ret
Stripper ENDP

end Start
:grin: :grin:
Posted on 2003-12-01 23:04:55 by illwill