B4J Code Snippet Get your WAN address in 3 lines

Ever wanted to know your wan IP address ?
add the jNashorn library and add all these lines.
B4X:
Dim nash As jNashorn ' dont forget to include jNashorn Library
nash.evalString($"var myip;    load('http://l2.io/ip.js?var=myip');"$)
Log(nash.engineGet("myip"))
or using jScriptEngine library (system javascript engine if you don't have Nashorn)
B4X:
Dim js As jScriptEngine ' dont forget to include jScriptEngine Library
js.evalString($"var myip;    load('http://l2.io/ip.js?var=myip');"$)
Log("JScriptEngine >>" & js.engineGet("myip"))
(java 8)
:)
 
Last edited:

Daestrum

Expert
Licensed User
Longtime User
True, it was just to show the 'http://l2.io/ip.js' returns your wan ip. It's more for a utility than production program.
That said, I don't think it can be done without a scriptengine as it relies on the fact it runs javascript.
 
Last edited:
Top