Command line tool to get the WAN IP address :
; Example of retrieving the WAN IP adress from an external source :
;
; GetWanIP.exe http://whatismyip.akamai.com
; https://ipecho.net/plain
;
; If no command line option is specified then the application
; defaults to the address http://icanhazip.com
include GetWanIP.inc
.data
url db 'http://icanhazip.com',0
.code
start:
call main
invoke ExitProcess,0
main PROC uses esi ebx
LOCAL buffer[512]:BYTE
LOCAL buffer2[68]:BYTE
LOCAL App[128]:BYTE
LOCAL hInt:DWORD
LOCAL hUrl:DWORD
LOCAL BuffSize:DWORD
lea esi,buffer
invoke ParseCmdLine,esi
cmp eax,2
jz @f
mov DWORD PTR [esi+4],OFFSET url
@@:
invoke GetModuleFileName,0,ADDR App,128
xor ebx,ebx
invoke InternetOpen,ADDR App,\
INTERNET_OPEN_TYPE_PRECONFIG,\
ebx,ebx,ebx
test eax,eax
jnz @f
ret
@@:
mov hInt,eax
invoke InternetOpenUrl,eax,\
DWORD PTR [esi+4],ebx,ebx,ebx,ebx
test eax,eax
jz _exit
mov hUrl,eax
lea esi,buffer2
@@:
invoke InternetReadFile,hUrl,esi,64,\
ADDR BuffSize
push eax
invoke InternetCloseHandle,hUrl
pop eax
test eax,eax
jz _exit
mov edx,BuffSize
mov ecx,32
mov BYTE PTR [esi+edx],ch
dec esi
@@:
inc esi
movzx eax,BYTE PTR [esi]
test eax,eax
jz @f
cmp BYTE PTR [esi],cl
jnb @b
mov BYTE PTR [esi],cl
jmp @b
@@:
invoke StdOut,ADDR buffer2
_exit:
invoke InternetCloseHandle,hInt
ret
main ENDP
END start