DNS query: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
 
(3 intermediate revisions by 3 users not shown)
Line 1,031:
2001:200:dff:fff1:216:3eff:feb1:44d7
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vb">#include "win\winsock2.bi"
 
Function GetSiteAddress(stuff As String = "www.freebasic.net") As Long
Dim As WSADATA _wsadate
Dim As in_addr addr
Dim As hostent Ptr res
Dim As Integer i = 0
WSAStartup(MAKEWORD(2,2),@_wsadate)
res = gethostbyname(stuff)
If res Then
Print !"\nURL: "; stuff
While (res->h_addr_list[i] <> 0)
addr.s_addr = *(Cast (Ulong Ptr,res->h_addr_list[i]))
Print "IPv4 address: ";*inet_ntoa(addr)
i+=1
Wend
WSACleanup()
Return 1
Else
Print "website error?"
Return 0
End If
End Function
 
GetSiteAddress "rosettacode.org"
GetSiteAddress "www.kame.net"
 
Sleep</syntaxhighlight>
{{out}}
<pre>URL: rosettacode.org
IPv4 address: 108.175.15.182
IPv4 address: 74.208.203.152
 
URL: www.kame.net
IPv4 address: 210.155.141.200</pre>
 
=={{header|Frink}}==
Line 1,045 ⟶ 1,084:
 
=={{header|FutureBasic}}==
FB has several ways to query a DNS server,. includingIn thisFB code7.0.23 the unix statement/function was added making such queries trivial:
<syntaxhighlight lang="futurebasic">
print unix @"nslookup -querytype=A www.kame.net"
HandleEvents
</syntaxhighlight>
Classic FB:
<syntaxhighlight>
Str255 UnixCommand
Str255 UnixResponse
Line 1,190 ⟶ 1,234:
 
=={{header|Java}}==
This is the same implementation as below, just less code
<syntaxhighlight lang="java">
import java.net.InetAddress;
import java.net.UnknownHostException;
</syntaxhighlight>
<syntaxhighlight lang="java">
public static void main(String[] args) throws UnknownHostException {
/* 'getAllByName' will use the system configured 'resolver' */
for (InetAddress ip : InetAddress.getAllByName("www.kame.net"))
System.out.println(ip.getHostAddress());
}
</syntaxhighlight>
<pre>
210.155.141.200
2001:2f0:0:8800:226:2dff:fe0b:4311
2001:2f0:0:8800:0:0:1:1
</pre>
<br />
An alternate demonstration
<syntaxhighlight lang="java">import java.net.InetAddress;
import java.net.Inet4Address;
Line 2,011 ⟶ 2,074:
 
However, if Wren is embedded in (say) a suitable Go program, then we can ask the latter to do it for us.
<syntaxhighlight lang="ecmascriptwren">/* dns_queryDNS_query.wren */
 
class Net {
Line 2,022 ⟶ 2,085:
which we embed in the following Go program and run it:
{{libheader|WrenGo}}
<syntaxhighlight lang="go">/* go run dns_queryDNS_query.go */
 
package main
Line 2,045 ⟶ 2,108:
func main() {
vm := wren.NewVM()
fileName := "dns_queryDNS_query.wren"
methodMap := wren.MethodMap{"static lookupHost(_)": lookupHost}
classMap := wren.ClassMap{"Net": wren.NewClass(nil, nil, methodMap)}
9,476

edits