Android Question How to resolve Domain-name to IPv6 address ?

fs007

Member
My task is to connect to a server, which is behind an ipv6 router. Domain name of the router is known via DynDNS. In order to address a server behind this router, i have to modify the routers WAN IPv6 address device identifier part, means i need to know this whole ip-address .

So my question is: How to resolve in B4A a hostname to its ip address ??? Basicly i need something like "nslookup" or php's "dns_get_record()"
There has been a method called "resolvehost", but this is depreciated.
 

fs007

Member
Thank you for replying, but I suspect, you didn't get my question fully:
1. I know the domain name. Let's say "abc.ddynddns.com".
2. This domain resolves to an ipv6 adress, let's say "x001:y002:z003:r004:s005:w006:p007:t008". So this is the non static wan address of my router.
3. The ipv6 address of the host ("behind" this router) has a SLAAC adress of let's say "x001:y002:z003:r004:xxxx:yyyy:zzzz:qqqq". SLAAC means xxxx:yyyy:zzzz:qqqq is calculated out of the hosts mac-address. So it is NOT s005:w006:p007:t008

In order to access this host from wan, i have to know it's full address (x001:y002:z003:r004:xxxx:yyyy:zzzz:qqqq). I know it's mac address, so i can calculate xxxx:yyyy:zzzz:qqqq easily, but i still need to know x001:y002:z003:r004. The only way to get this part of the address is to dns resolve abc.ddynddns.com.
And that's the reason why i need something like nslookup which would give me this address.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
if what you want is a normal ip address resolution from a host name, the enclosed will give you that:

B4X:
Activity_Create
    DisableStrictMode
    Dim lookup As JavaObject
    lookup.initializestatic("java.net.InetAddress")
    Dim ipaddress As String = lookup.runmethodJO("getByName", Array("www.google.com")).RunMethod("getHostAddress",Null)
    Log(ipaddress)
End Sub

Sub DisableStrictMode
    Dim jo As JavaObject
    jo.InitializeStatic("android.os.Build.VERSION")
    If jo.GetField("SDK_INT") > 9 Then
        Dim policy As JavaObject
        policy = policy.InitializeNewInstance("android.os.StrictMode.ThreadPolicy.Builder", Null)
        policy = policy.RunMethodJO("permitAll", Null).RunMethodJO("build", Null)
        Dim sm As JavaObject
        sm.InitializeStatic("android.os.StrictMode").RunMethod("setThreadPolicy", Array(policy))
    End If
    
End Sub

and you need the JavaObject library.
 
Upvote 0

fs007

Member
Thanks again for these answers.
Three last questions:
1. Does this code work for ipv6 too ?
2. Where do i get JavaObject library for B4A ?
3. Network operation in main thread doesn't sound very good. Wouldn't it be possible, to code a DNS-Request from scratch in B4A ? (It's just a UDP packet to send and parse the answer, isn't it ?)
 
Upvote 0
Top