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
Thanks Vortex,
This is useful, even if just for the URL.
I always wanted to find out my TRUE IP without needing to use another web site though. Just seems ridiculous I can't get my true IP from my own computer or modem through software without asking a web site to send it to me.
Maybe some sort of ping trace then at least it is just a ping.
Anyone has solved this question without hitting an external web site, and without a DNS service?
John Z
Hi John Z,
Thanks. I am afraid there is no easy way to get the WAN IP without referring to external sources. The only other method is to access the web interface of your router to check the WAN IP.
Yup, so I appreciate your code contribution even more!
Thanks
John Z
Hi John,
There is an easier method to get the WAN IP address, nslookup does the job :
nslookup myip.opendns.com. resolver1.opendns.com
Hi Vortex,
Wow worked great !
Can even pipe it to a file.
Thanks so much,
John Z