Parent nameservers - php

I've been trying to find out how to detect what parent nameserver is associated with a domain name. For example, when you search for a domain name using intoDNS, it displays results for both the 'normal' and parent nameservers. They mention what the parent nameserver is, like this:
k.gtld-servers.net was kind enough to give us that information.
But how did they know they had to query this specific nameserver? A few examples of what the parent nameserver is:
stackoverflow.com k.gtld-servers.net
google.com c.gtld-servers.net
ycombinator.com a.gtld-servers.net
asp.net g.gtld-servers.net
google.nl sns-pb.isc.org
google.de z.nic.de
It seems all generic TLDs can be queried at a certain subdomain of gtld-servers.net.
Right now, I find the 'normal' nameservers in PHP like this:
$nameservers = dns_get_record($domain_name, DNS_NS);
So, I'd like to know, how can I find out what the parent nameserver is for a specific domain and how can I query this using PHP?
Update
I've found out that UNIX' nslookup tool accepts a server parameter. If it's left empty, it returns the same results as PHPs dns_get_record, but if it one of the root servers for that top-level domain as specified on http://www.iana.org/domains/root/db, it will return the same results as intoDNS lists as the results of the parent server.
The only problem left is how to query this specific server, as I'd greatly prefer not to use exec() to call nslookup directly. Does anyone know of an alternative to dns_get_record which does allow you to specify the server?

I've found out how to do it. I had to use NET_DNS2 PEAR package for this, because it allows you to specificy which DNS server to use. If I specify one of the servers listed in the file nickc mentioned:
http://www.iana.org/domains/root/db
(you have to use one of the servers for the top-level domain you're querying, it doesn't matter which one)
require 'Net/DNS2.php';
$server = gethostbyname('j.gtld-servers.net'); // 192.48.79.30
$r = new Net_DNS2_Resolver(array('nameservers' => array($server)));
$result = $r->query('stackoverflow.com', 'NS');
print_r ($result);
This will print:
...
[authority] => Array
(
[0] => Net_DNS2_RR_NS Object
(
[nsdname] => ns1.webfaction.com
[name] => webassay.com
[type] => NS
[class] => IN
[ttl] => 172800
[rdlength] => 17
[rdata] => ns1webfaction�
)
[1] => Net_DNS2_RR_NS Object
(
[nsdname] => ns2.webfaction.com
[name] => webassay.com
[type] => NS
[class] => IN
[ttl] => 172800
[rdlength] => 6
[rdata] => ns2�.
)
[2] => Net_DNS2_RR_NS Object
(
[nsdname] => ns3.webfaction.com
[name] => webassay.com
[type] => NS
[class] => IN
[ttl] => 172800
[rdlength] => 6
[rdata] => ns3�.
)
)
...
This matches the nameservers listed as returned by the parent server at intoDNS: http://www.intodns.com/stackoverflow.com

The name-servers for a particular domain are those that are designated in the zone file as a "NS" record. The hosts/servers you list are global/root servers that maintain information for the particular TLD of the domain in question.
If you want to find out what those are, you could look here: http://www.iana.org/domains/root/db

Related

PHP Custom Session Handler not working on some domains

We have several quality domains with the identical code base. We are converting from using the native PHP session handler to a custom session handler writing the session data to MySQL. On certain domains the session handling is broken because the session data written to the database is corrupted.
At first we thought it might have something to do with different PHP levels on the different domains. However, we have ruled this out as one domain where it is not working has the same PHP level as a domain where it is working.
This question seems similar to the one at
Custom Session Handler not working on PHP5.6 but does on PHP7. However, in our case the issue is not resolved by adding session_write_close().
Here is some debugging output from the two different instances that clearly shows what is happening. In each case, first a print_r of $_SESSION is shown, followed by the contents of the session data as it will be written to the database:
On first domain designated as "local":
Before write--session data via print_r:
Array ( [debug] => Array ( [0] => Session ID e2104hafmvtur2rsof78m918gs ) [scr_width] => 2560 [recent_page_view_history] => Array ( [0] => / [1] => / [2] => / [3] => / [4] => / [5] => / ) [my_user_label_full] => Independent Sales Rep [my_user_label_short] => Rep [opp_user_type_id] => 2 [opp_user_label_full] => Principal [opp_user_label_long] => New Line [opp_user_label_long_seo] => Independent Sales Companies & New Line [opp_user_label_short] => Principal [user_value_stmt] => Industry Expertise [opp_user_value_stmt] => Sales Opportunity [with_or_as] => as an Independent Sales Rep. This guide for companies that hire reps will help you understand how to be a better rep. [is_help_open] => 1 [referrer] => / [IE_warning_given] => 1 [link_mode] => 0 [isTouchScreen] => 0 [dynamicInputWording] => point your cursor at [dynamicInputWordingCapitalized] => Point your cursor at [devicePixelRatio] => 2 )
Before write--data passed into custom session handler write():
debug|a:1:{i:0;s:37:"Session ID e2104hafmvtur2rsof78m918gs";}scr_width|s:4:"2560";recent_page_view_history|a:6:{i:0;s:1:"/";i:1;s:1:"/";i:2;s:1:"/";i:3;s:1:"/";i:4;s:1:"/";i:5;s:1:"/";}my_user_label_full|s:21:"Independent Sales Rep";my_user_label_short|s:3:"Rep";opp_user_type_id|i:2;opp_user_label_full|s:9:"Principal";opp_user_label_long|s:8:"New Line";opp_user_label_long_seo|s:42:"Independent Sales Companies & New Line";opp_user_label_short|s:9:"Principal";user_value_stmt|s:18:"Industry Expertise";opp_user_value_stmt|s:17:"Sales Opportunity";with_or_as|s:117:"as an Independent Sales Rep. This guide for companies that hire reps will help you understand how to be a better rep.";is_help_open|b:1;referrer|s:1:"/";IE_warning_given|b:1;link_mode|i:0;isTouchScreen|s:1:"0";dynamicInputWording|s:20:"point your cursor at";dynamicInputWordingCapitalized|s:20:"Point your cursor at";devicePixelRatio|s:1:"2";
The above looks as expected and the website works normally.
On second domain designated as "dev":
Before write--session data via print_r:
Array ( [debug] => Array ( [0] => Session ID v301fcrls9ijktjtlc7n4gd3n5 ) [scr_width] => 2560 [recent_page_view_history] => Array ( [0] => /landing-page.php [1] => /landing-page.php [2] => /landing-page.php [3] => /landing-page.php [4] => /landing-page.php [5] => /landing-page.php ) [my_user_label_full] => Principal [my_user_label_short] => Principal [opp_user_type_id] => 1 [opp_user_label_full] => Independent Sales Rep [opp_user_label_long] => Sales Rep [opp_user_label_long_seo] => Independent Sales Rep [opp_user_label_short] => Rep [user_value_stmt] => Sales Opportunity [opp_user_value_stmt] => Industry Expertise [with_or_as] => with Independent Sales Reps. [is_help_open] => 1 [referrer] => /landing-page.php [IE_warning_given] => 1 [link_mode] => 0 [isTouchScreen] => 0 [dynamicInputWording] => point your cursor at [dynamicInputWordingCapitalized] => Point your cursor at [devicePixelRatio] => 2 [site_user_type] => 2 [lp_source] => register-external )
Before write--data passed into custom session handler write():
pQkKjjiuhsxKkLD5bG1pcvfRiU073NotPwuYW3TrIAEwiKACrZ1s6dbIQmOeo7430UQAYgu_GENi_KhZx4vSUdaV4iXmSOVxNZgoNC_7-xDzOMDdRo7zp3sk-_aEv3XyenNi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dFGHSyLcT1qGpDpZn0-ljpV_nzrYDXe6d2fsejqBZs_aWAZQFFJ7qMwUzVX53dzLgTf3ziAzPwPayQl8NBd8VptIKiVLZfN1v0tofRPuNXXVUd2s.
As you can see, rather than the special serialized version of the data, it becomes obfuscated in some way. And session handling is broken.
On a domain designated as "qa", the output is identical to "local". Please note that "local" has php 7.1, while both "dev" and "qa" have php 5.6. The php.ini files for all three domains have identical settings for session.* variables.
Question: what is the cause of the obfuscation of session data?
We found the solution. It was that Suhosin was enabled on some domains but not on others. Suhosin automatically encrypts the session data.
We will be losing Suhosin as we move forward as it appears to not be an integral part of PHP 7+. Either is is not available, or does not compile properly.

PHP's dns_get_record returning subdomain record instead of domain record

When I'm using dns_get_record for a domain that exists like google.com, everything works fine but if I use it on a domain that doesn't exist, the function gets info from a subdomain on our domain for example test.example.com, how can I prevent that?
// Test with working domain
var_dump( dns_get_record('google.com', DNS_A) );
/* works, returns
Array
(
[host] => google.com
[class] => IN
[ttl] => 299
[type] => A
[ip] => 172.217.12.142
)
*/
// Test with invalid domain on our website (example.com)
var_dump( dns_get_record('invalidtestingname.com', DNS_A) );
/* Doesn't work, pretend it's a subdomain
Array
(
[host] => invalidtestingname.com.example.com
[class] => IN
[ttl] => 299
[type] => A
[ip] => xxx.xxx.xxx.xxx
)
*/
If anyone has that problem, add a "dot" at the end of the domain name, for example, instead of
dns_get_record('invalidtestingname.com', DNS_A);
Do this:
dns_get_record('invalidtestingname.com.', DNS_A);
Then PHP won't try to check for a subdomain of your own domain and it will search correctly. Not sure how come nobody had that problem before, there aren't even any comments about this on php.net

Checking for an MX record with getmxrr() or dns_get_record() returns incorrect information

I am currently attempting to check the validity of an email address by first checking if an MX record exists, using getmxrr() or dns_get_record() with PHP 7 on a DigitalOcean droplet.
In my example (which returns the incorrect response), I am attempting to check an email address on the domain “nuwatches.com”. Using dns_get_record(”nuwatches.com”, DNS_ALL), I’m returned an array that DOES include an MX record, even though I know this does not exist in reality:
[5] => Array (
[host] => nuwatches.com.com
[class] => IN
[ttl] => 27
[type] => MX
[pri] => 1
[target] => mail.user-mail.net
)
However, if I use nslookup directly from the console on the DigitalOcean droplet, I’m correctly told that no MX record exists.
In addition, if I run the dns_get_record() function on a different droplet, or using an online PHP code runner, I’m also given the correct answer (which is that no MX record exists).
I’ve spoken to DigitalOcean support and they suggest there’s something strange happening with PHP on that particular droplet, perhaps with caching issues, but I can’t at all figure out what might be causing the discrepancy, especially as I'm not caching anything myself.
As it stands, my only option to get the correct response on this droplet is to run nslookup and then parse the result, but I would like to use dns_get_record() if possible.
I’d appreciate any suggestions. Thanks!
I am having similar problems with dns_get_record() when calling it with the default value for record type DNS_ANY or when calling it with DNS_ALL.
php dns_get_records( host, type ) is returning false with type=DNS_ALL but returns DNS records with DNS_TXT or DNS_A
A solution that worked for me was to use:
dns_get_record( ”nuwatches.com”, DNS_MX )
I am still investigating the reason behind this behaviour.
You can try to use a 3rd party PHP library for that.
I've just tested it and it worked for me.
bluelibraries/dns
sample
use BlueLibraries\Dns\Facade\DNS;
use BlueLibraries\Dns\Records\RecordTypes;
$records = DNS::getRecords('nuwatches.com', RecordTypes::MX);
print_r($records);
result
Array
(
[0] => BlueLibraries\Dns\Records\Types\MX Object
(
[data:protected] => Array
(
[host] => nuwatches.com
[ttl] => 3600
[class] => IN
[type] => MX
[pri] => 1
[target] => localhost
)
)
)

ip2location: get all ip(s) belonged to a domain

I want to have all ip(s) belonged to a domain, e.g. google.com, I recently have a look at this, https://github.com/ip2location/ip2location-cakephp. So, what I am going to do is likes this:
<?php
// clientIp() will iterate from 1.1.1.1 to 255.255.255.255
App::uses('IP2LocationCore', 'IP2Location.Model');
$IP2Location = new IP2LocationCore();
$record = $IP2Location->get($this->request->clientIp());
if(strcmp($record->domainName, 'google.com')) {
// log the ip to a text file
}
?>
My question is: is this solution feasible?, and anyway better than this?
I'm not much of a PHP person, so consider that in my reply!
It seems that what ip2location does is to take an IP address, and gives you its location. It does this (I imagine) by compiling information from assorted data sources.
However you need to start with an IP Address and it will give you the reverse domain that is associated with that. This could well be different than the forward look up address.
For instance I have a hostname vm.example.com that I use to point to a remote desktop session on Azure. If you did a reverse lookup on that address you would not get any information on my domain, you would get the Azure domain, because that's where the reverse is registered.
and as far as I'm aware, unless zone transfers are enabled, there is no way to get all of the hostnames in a domain. At least not without incrementing through the entire domain.
Is there a specific reason you want to do this?
Try using the PHP function gethostbynamel.
<?php
$hosts = gethostbynamel('google.com');
print_r($hosts);
?>
This will for example return:
Array
(
[0] => 173.194.113.35
[1] => 173.194.113.41
[2] => 173.194.113.46
[3] => 173.194.113.34
[4] => 173.194.113.40
[5] => 173.194.113.39
[6] => 173.194.113.33
[7] => 173.194.113.37
[8] => 173.194.113.32
[9] => 173.194.113.38
[10] => 173.194.113.36
)

Fetch Report using GoodData API

I have created a report on my GoodData UI. Now I want to fetch this report using the API. I spent hours digging the API docs but I am unable to find a simple way to do so.
If I try gdc/execute/raw/, it returns
[error] => Array
(
[parameters] => Array
(
[0] => execute
)
[requestId] => 53fPgKcFdkjf8PZ5:4n6x9lp9vk3ydbvs
[component] => GDC
[errorClass] => GDC::Exception::NotFound
[message] => resource %s not found
)
If I try gdc/xtab2/executor3 it returns
[error] => Array
(
[parameters] => Array
(
[0] => report_req
[1] => STRUCTURE INVALID - name of structure:'ReportReq'(tag:report_req), /report_req/ExecutionObject: Object does not match any alternative. Alternatives tried : [STRUCTURE INVALID - name of structure:'ReportReq' ...]
)
[requestId] => a0yRpNUpCPRsbPS0:6nagmwaw61h5g2bn
[component] => Apache::REST
[errorClass] => GDC::Exception::User
[message] => Checking '%s', result %s
)
Your requests got 404 and 400 statuses respectively.
When you tried to use 'gdc/execute/raw/' the call that reached our side was: "request="POST /gdc/execute/raw/ HTTP/1.1"", instead of that it should look like "POST /gdc/app/projects/{your_project_id}/execute/raw/ HTTP/1.1", that's the reason your are getting a 'NotFound' error. Regarding 'gdc/xtab2/executor3' there's apparently something wrong within the body of the call.
Please post your calls here, their bodies and how exactly you are making them, or open a support ticket with those details at https://support.gooddata.com/home so that we can investigate further.
Ultimately I followed this code piece https://gist.github.com/gnilrets/b9d2ce9890d8aaa07042
Much better than reading the whole GoodData API documentation.

Categories