$cat dns.php
<?php
$host = "ipv4.tlund.se";
var_dump(dns_get_record($host, DNS_A + DNS_AAAA));
echo "----\n";
var_dump(dns_get_record($host, DNS_A));
?>
##Fedora release 22 (Twenty Two) 4.4.13-200.fc22.x86_64
$ php --version
PHP 5.6.23 (cli) (built: Jun 22 2016 06:48:45)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
$ php dns.php
array(1) {
[0]=>
array(5) {
["host"]=>
string(10) "digitec.ch"
["class"]=>
string(2) "IN"
["ttl"]=>
int(60)
["type"]=>
string(1) "A"
["ip"]=>
string(14) "174.129.25.170"
}
}
----
array(1) {
[0]=>
array(5) {
["host"]=>
string(10) "digitec.ch"
["class"]=>
string(2) "IN"
["ttl"]=>
int(60)
["type"]=>
string(1) "A"
["ip"]=>
string(14) "174.129.25.170"
}
}
##FreeBSD 10.3-RELEASE-p4
$ php -v
PHP 5.6.23 (cli) (built: Jul 2 2016 01:42:17)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
$ php dns.php
PHP Warning: dns_get_record(): DNS Query failed in /root/dns.php on line 5
bool(false)
----
array(1) {
[0]=>
array(5) {
["host"]=>
string(10) "digitec.ch"
["class"]=>
string(2) "IN"
["ttl"]=>
int(53)
["type"]=>
string(1) "A"
["ip"]=>
string(14) "174.129.25.170"
}
}
##Fedora C code
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
int main() {
u_char ans[8192];
//res_state state;
res_init();
int i = res_search("ipv4.tlund.se", 28, 0, ans, sizeof(ans));
printf("status: %d\n", i);
return i;
}
run it
gcc -lresolv -o dns_rec dns_req.c && ./dns_rec
##FreeBSD
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
int main() {
res_init();
u_char ans[8192];
//int i = res_search("ipv4.tlund.se", 28, 0, ans, sizeof(ans));
int i = res_search("google.com", 28, 0, ans, sizeof(ans));
printf("status: %d\n", i);
return i;
}
run it
$ clang -o dns_rec dns_req.c && ./dns_rec